結果

問題 No.13 囲みたい!
ユーザー yaoshimaxyaoshimax
提出日時 2015-02-10 12:55:31
言語 Python2
(2.7.18)
結果
TLE  
実行時間 -
コード長 792 bytes
コンパイル時間 655 ms
コンパイル使用メモリ 6,644 KB
実行使用メモリ 10,720 KB
最終ジャッジ日時 2023-09-05 22:42:07
合計ジャッジ時間 7,545 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 11 ms
5,980 KB
testcase_01 AC 11 ms
5,876 KB
testcase_02 AC 12 ms
5,848 KB
testcase_03 AC 33 ms
6,204 KB
testcase_04 AC 17 ms
6,144 KB
testcase_05 TLE -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

W,H=map(int,raw_input().split())
M=[]
for i in range(H):
   Ms = map(int,raw_input().split())
   M.append(Ms)


dx=[1,0,-1,0]
dy=[0,1,0,-1]

for a in range(H):
   for b in range(W):
      arrived=[[False for i in range(W)] for j in range(H)]
      st = [(a,b,1)]
      while len(st)!=0:
         i,j,dist = st.pop()
         if arrived[i][j]:
            continue
         arrived[i][j]=True
         for x,y in zip(dx,dy):
            ni = i+x
            nj = j+y
            if ni >= 0 and ni < H and nj >= 0 and nj <W:
               if M[ni][nj]==M[i][j]:
                  if a== ni and b == nj and dist >= 3:
                     print 'possible'
                     exit()
                  elif not arrived[ni][nj]:
                     st.append((ni,nj,dist+1))
print 'impossible'
0