結果
| 問題 | No.13 囲みたい! |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2015-02-23 16:25:48 |
| 言語 | PyPy2 (7.3.20) |
| 結果 |
AC
|
| 実行時間 | 99 ms / 5,000 ms |
| + 402µs | |
| コード長 | 634 bytes |
| 記録 | |
| コンパイル時間 | 73 ms |
| コンパイル使用メモリ | 81,016 KB |
| 実行使用メモリ | 93,440 KB |
| 最終ジャッジ日時 | 2026-07-17 10:23:17 |
| 合計ジャッジ時間 | 2,614 ms |
|
ジャッジサーバーID (参考情報) |
judge1_0 / judge3_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 16 |
ソースコード
import sys
sys.setrecursionlimit(10000)
dxy = zip([1,0,-1,0],[0,1,0,-1])
def dfs(x,y,c):
A[y][x] = -c
res = False
cnt = 0
for dx,dy in dxy:
nx,ny = x+dx,y+dy
if 0 <= nx < W and 0 <= ny < H:
if A[ny][nx] == c:
res |= dfs(nx,ny,c)
elif A[ny][nx] == -c:
cnt += 1
return res or cnt > 1
W,H = map(int,raw_input().split())
A = [map(int,raw_input().split()) for i in xrange(H)]
ans = False
for 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"