結果
| 問題 | No.13 囲みたい! | 
| コンテスト | |
| ユーザー |  yaoshimax | 
| 提出日時 | 2015-02-10 13:10:19 | 
| 言語 | Python2 (2.7.18) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 52 ms / 5,000 ms | 
| コード長 | 829 bytes | 
| コンパイル時間 | 395 ms | 
| コンパイル使用メモリ | 6,912 KB | 
| 実行使用メモリ | 6,820 KB | 
| 最終ジャッジ日時 | 2024-10-13 10:40:44 | 
| 合計ジャッジ時間 | 1,442 ms | 
| ジャッジサーバーID (参考情報) | judge5 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 16 | 
ソースコード
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'
            
            
            
        