結果
| 問題 | No.13 囲みたい! |
| コンテスト | |
| ユーザー |
Tawara
|
| 提出日時 | 2016-07-27 23:52:13 |
| 言語 | PyPy2 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 120 ms / 5,000 ms |
| コード長 | 657 bytes |
| 記録 | |
| コンパイル時間 | 148 ms |
| コンパイル使用メモリ | 77,084 KB |
| 最終ジャッジ日時 | 2025-12-03 21:08:33 |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 16 |
ソースコード
from collections import deque dxy = ((1,0),(0,1),(-1,0),(0,-1)) W,H = map(int,raw_input().split()) M = [map(int,raw_input().split()) for i in xrange(H)] Gone = [[False]*W for i in xrange(H)] def bfs(h,num): if Gone[h[1]][h[0]]: return False Q = deque() Q.append(((-1,-1),h)) while Q: b,h = Q.popleft() if Gone[h[1]][h[0]]: return True Gone[h[1]][h[0]] = True for dx,dy in dxy: nxt = (h[0] + dx, h[1] + dy) if nxt != b and 0 <= nxt[0] < W and 0 <= nxt[1] < H and M[nxt[1]][nxt[0]] == num: Q.append((h,nxt)) return False for i in xrange(H): for j in xrange(W): if bfs((j,i),M[i][j]): print "possible" quit() print "impossible"
Tawara