結果
| 問題 |
No.13 囲みたい!
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2016-09-21 14:51:14 |
| 言語 | Python2 (2.7.18) |
| 結果 |
AC
|
| 実行時間 | 42 ms / 5,000 ms |
| コード長 | 895 bytes |
| コンパイル時間 | 54 ms |
| コンパイル使用メモリ | 6,784 KB |
| 実行使用メモリ | 8,320 KB |
| 最終ジャッジ日時 | 2024-11-17 10:23:58 |
| 合計ジャッジ時間 | 1,154 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 16 |
ソースコード
W, H = map(int, raw_input().split())
board = [map(int, raw_input().split()) for _ in xrange(H)]
visited = set()
dr = [0, 0, 1, -1]
dc = [1, -1, 0, 0]
def dfs(start):
stack = [start]
while len(stack) > 0:
row, col = stack.pop()
if (row, col) in visited:
return True
visited.add((row, col))
for i in xrange(4):
nrow = row+dr[i]
ncol = col+dc[i]
if nrow < 0 or nrow >= H or ncol < 0 or ncol >= W:
continue
if (nrow, ncol) in visited:
continue
if board[nrow][ncol] != board[row][col]:
continue
stack.append((nrow, ncol))
return False
for i in xrange(H):
for j in xrange(W):
if (i, j) in visited:
continue
if dfs((i, j)):
print 'possible'
exit()
print 'impossible'