結果

問題 No.13 囲みたい!
ユーザー pluto77pluto77
提出日時 2017-08-02 13:39:39
言語 Python2
(2.7.18)
結果
AC  
実行時間 36 ms / 5,000 ms
コード長 687 bytes
コンパイル時間 246 ms
コンパイル使用メモリ 6,784 KB
実行使用メモリ 10,624 KB
最終ジャッジ日時 2024-04-19 13:26:59
合計ジャッジ時間 1,442 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 11 ms
6,016 KB
testcase_01 AC 10 ms
6,016 KB
testcase_02 AC 11 ms
6,144 KB
testcase_03 AC 28 ms
10,624 KB
testcase_04 AC 15 ms
6,400 KB
testcase_05 AC 36 ms
9,856 KB
testcase_06 AC 18 ms
6,784 KB
testcase_07 AC 30 ms
6,656 KB
testcase_08 AC 32 ms
6,528 KB
testcase_09 AC 31 ms
6,528 KB
testcase_10 AC 15 ms
6,272 KB
testcase_11 AC 27 ms
6,528 KB
testcase_12 AC 13 ms
6,144 KB
testcase_13 AC 17 ms
6,144 KB
testcase_14 AC 19 ms
6,144 KB
testcase_15 AC 11 ms
6,016 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#yuki_13
import sys

sys.setrecursionlimit(10000)

def dfs(y,x,py,px,n):
 global suc
 if suc: return
 done[y][x]=True
 for i in xrange(4):
  ny=y+dy[i]
  nx=x+dx[i]
  if not (0<=ny and ny<H and 0<=nx and nx<W): continue
  if ny==py and nx==px: continue
  if a[ny][nx]!=n: continue
  if done[ny][nx]:
   suc=True
   return
  dfs(ny,nx,y,x,n)

W,H=map(int,raw_input().split())
a=[]
for i in xrange(H):
 temp=map(int,raw_input().split())
 a.append(temp)
done=[[0 for i in xrange(W)] for j in xrange(H)]
dx=[-1,0,1,0]
dy=[0,1,0,-1]
suc=False

for i in xrange(H):
 for j in xrange(W):
  if suc: break
  if done[i][j]: continue
  dfs(i,j,i,j,a[i][j])
print 'possible' if suc else 'impossible'
0