結果
| 問題 | No.13 囲みたい! | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2014-11-28 13:50:35 | 
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 55 ms / 5,000 ms | 
| コード長 | 579 bytes | 
| コンパイル時間 | 140 ms | 
| コンパイル使用メモリ | 12,800 KB | 
| 実行使用メモリ | 12,288 KB | 
| 最終ジャッジ日時 | 2024-10-13 10:39:32 | 
| 合計ジャッジ時間 | 1,379 ms | 
| ジャッジサーバーID (参考情報) | judge4 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 16 | 
ソースコード
w,h=map(int,input().split())
m=[[int(i) for i in input().split()]+[0] for _ in range(h)]+[[0]*w]
checked=set()
def dfs(x,y):
  if (x,y) in checked: return False
  r=[(0,-1),(1,0),(-1,0),(0,1)]
  c=m[y][x]
  stack=[(-1,x,y)]
  while len(stack):
    dir,tx,ty=stack.pop()
    if m[ty][tx]==c:
      if (tx,ty) in checked: return True
      checked.add((tx,ty))
      for i,(dx,dy) in enumerate(r):
        if i!=dir:
          stack.append((3-i,tx+dx,ty+dy))
print( "possible" if any([any([dfs(x,y) for x in range(w)]) for y in range(h)]) else "impossible")
            
            
            
        