結果
問題 | No.13 囲みたい! |
ユーザー |
|
提出日時 | 2015-02-23 16:25:48 |
言語 | Python2 (2.7.18) |
結果 |
RE
|
実行時間 | - |
コード長 | 634 bytes |
コンパイル時間 | 57 ms |
コンパイル使用メモリ | 7,040 KB |
実行使用メモリ | 14,976 KB |
最終ジャッジ日時 | 2024-06-23 21:59:06 |
合計ジャッジ時間 | 1,263 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 15 RE * 1 |
ソースコード
import syssys.setrecursionlimit(10000)dxy = zip([1,0,-1,0],[0,1,0,-1])def dfs(x,y,c):A[y][x] = -cres = Falsecnt = 0for dx,dy in dxy:nx,ny = x+dx,y+dyif 0 <= nx < W and 0 <= ny < H:if A[ny][nx] == c:res |= dfs(nx,ny,c)elif A[ny][nx] == -c:cnt += 1return res or cnt > 1W,H = map(int,raw_input().split())A = [map(int,raw_input().split()) for i in xrange(H)]ans = Falsefor y in xrange(H):for x in xrange(W):if A[y][x] > 0:ans |= dfs(x,y,A[y][x])print "possible" if ans else "impossible"