結果
| 問題 |
No.13 囲みたい!
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-09-21 10:38:19 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 98 ms / 5,000 ms |
| コード長 | 2,631 bytes |
| コンパイル時間 | 272 ms |
| コンパイル使用メモリ | 81,988 KB |
| 実行使用メモリ | 78,720 KB |
| 最終ジャッジ日時 | 2024-06-24 11:26:35 |
| 合計ジャッジ時間 | 2,401 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 16 |
コンパイルメッセージ
Main.py:33: SyntaxWarning: list indices must be integers or slices, not tuple; perhaps you missed a comma? que += [i][j - 1, 3]
ソースコード
W, H = map(int, input().split())
M = [list(map(int, input().split())) for i in range(H)]
visited = [[0] * W + [-1] for i in range(H)] + [[-1] * (W + 1)]
from collections import deque
for i in range(H):
for j in range(W):
if visited[i][j] == 0:
que = []
X = M[i][j]
if visited[i + 1][j] == 0 and M[i + 1][j] == X:
visited[i + 1][j] = 1
que += [i + 1, j, 0]
if visited[i][j + 1] == 0 and M[i][j + 1] == X:
visited[i][j + 1] = 1
que += [i, j + 1, 1]
if visited[i - 1][j] == 0 and M[i - 1][j] == X:
visited[i - 1][j] = 1
que += [i - 1, j, 2]
if visited[i][j - 1] == 0 and M[i][j - 1] == X:
visited[i][j - 1] = 1
que += [i][j - 1, 3]
visited[i][j] = 1
que = deque(que)
while que:
x, y, q = que.popleft(), que.popleft(), que.popleft()
if visited[x - 1][y] != -1 and M[x - 1][y] == X and q != 0:
if visited[x - 1][y]:
print('possible')
exit()
else:
visited[x - 1][y] = 1
que.extend([x - 1, y, 2])
if visited[x + 1][y] != -1 and M[x + 1][y] == X and q != 2:
if visited[x + 1][y]:
print('possible')
exit()
else:
visited[x + 1][y] = 1
que.extend([x + 1, y, 0])
if visited[x][y - 1] != -1 and M[x][y - 1] == X and q != 1:
if visited[x][y - 1]:
print('possible')
exit()
else:
visited[x][y - 1] = 1
que.extend([x, y - 1, 3])
if visited[x][y + 1] != -1 and M[x][y + 1] == X and q != 3:
if visited[x][y + 1]:
print('possible')
exit()
else:
visited[x][y + 1] = 1
que.extend([x, y + 1, 1])
print('impossible')