Skip to content

Instantly share code, notes, and snippets.

@nishidy
Created July 9, 2015 08:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nishidy/376e5627ca92ffba42be to your computer and use it in GitHub Desktop.
Save nishidy/376e5627ca92ffba42be to your computer and use it in GitHub Desktop.
Round 2 2015: Problem A. Pegman (small/large)
def crosscheck(ri,ci,R,C,rect):
for cidx in range(ci+1,C):
if rect[ri][cidx] != '.':
return "COK"
for cidx in range(ci-1,-1,-1):
if rect[ri][cidx] != '.':
return "COK"
for ridx in range(ri+1,R):
if rect[ridx][ci] != '.':
return "CNGROK"
for ridx in range(ri-1,-1,-1):
if rect[ridx][ci] != '.':
return "CNGROK"
return "NG"
def dircheck(ri,ci,R,C,drt):
if drt=='^':
for ridx in range(ri-1,-1,-1):
if rect[ridx][ci] != '.':
return True
if drt=='>':
for cidx in range(ci+1,C,1):
if rect[ri][cidx] != '.':
return True
if drt=='v':
for ridx in range(ri+1,R,1):
if rect[ridx][ci] != '.':
return True
if drt=='<':
for cidx in range(ci-1,-1,-1):
if rect[ri][cidx] != '.':
return True
return False
T=int(raw_input())
t=0
while t<T:
a=0
R,C=map(lambda x:int(x),raw_input().split())
r=0
rect=[]
while r<R:
rect.append(raw_input())
r+=1
r=0
for ri in range(0,R):
breakflag=False
for ci in range(0,C):
if rect[ri][ci] != '.':
res=crosscheck(ri,ci,R,C,rect)
if res=="COK":
break
elif res=="CNGROK":
continue
else:
breakflag=True
break
if breakflag:
break
if breakflag:
t+=1
print "Case #%d: IMPOSSIBLE"%(t,)
else:
for ri in range(0,R):
for ci in range(0,C):
if rect[ri][ci] != '.':
if not dircheck(ri,ci,R,C,rect[ri][ci]):
a+=1
t+=1
print "Case #%d: %d"%(t,a)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment