結果

問題 No.13 囲みたい!
ユーザー yaoshimaxyaoshimax
提出日時 2015-02-10 13:10:19
言語 Python2
(2.7.18)
結果
AC  
実行時間 51 ms / 5,000 ms
コード長 829 bytes
コンパイル時間 821 ms
コンパイル使用メモリ 7,200 KB
実行使用メモリ 6,656 KB
最終ジャッジ日時 2024-04-21 12:16:29
合計ジャッジ時間 1,689 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 9 ms
6,272 KB
testcase_01 AC 9 ms
6,400 KB
testcase_02 AC 9 ms
6,144 KB
testcase_03 AC 29 ms
6,656 KB
testcase_04 AC 13 ms
6,272 KB
testcase_05 AC 51 ms
6,528 KB
testcase_06 AC 17 ms
6,528 KB
testcase_07 AC 47 ms
6,528 KB
testcase_08 AC 44 ms
6,656 KB
testcase_09 AC 42 ms
6,656 KB
testcase_10 AC 15 ms
6,272 KB
testcase_11 AC 33 ms
6,656 KB
testcase_12 AC 11 ms
6,272 KB
testcase_13 AC 20 ms
6,400 KB
testcase_14 AC 20 ms
6,272 KB
testcase_15 AC 10 ms
6,400 KB
権限があれば一括ダウンロードができます

ソースコード

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]

arrived=[[False for i in range(W)] for j in range(H)]
for a in range(H):
   for b in range(W):
      st = [(a,b,-1,-1)]
      while len(st)!=0:
         i,j,pi,pj = 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 not arrived[ni][nj]:
                     st.append((ni,nj,i,j))
                  elif pi!=-1:
                     if (ni,nj)!=(i,j) and (ni,nj)!=(pi,pj):
                        print 'possible'
                        exit()
print 'impossible'
0