Skip to content

Instantly share code, notes, and snippets.

@palcu
Created November 26, 2013 21:24
Show Gist options
  • Save palcu/7666521 to your computer and use it in GitHub Desktop.
Save palcu/7666521 to your computer and use it in GitHub Desktop.
import math;f=open('i');r=f.readline
for _ in range(1,int(r())+1):
m=[];s=b=0
for i in range(int(r())):m.append([1 if j=='#' else 0 for j in r()]);s+=sum(m[i])
a=int(math.sqrt(s))
while not filter(None,m[0]):m.pop(0)
l=[i for i,x in enumerate(m[0]) if x];x=l[0];y=l[-1]
for v in m:
if a!=sum(v[x:y+1]):break
else:b+=a
if a*a!=s or b!=s:print "Case #%s: NO"%_
else:print "Case #%s: YES"%_
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment