結果
問題 | No.13 囲みたい! |
ユーザー | mlihua09 |
提出日時 | 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 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 58 ms
65,796 KB |
testcase_01 | AC | 58 ms
66,896 KB |
testcase_02 | AC | 58 ms
66,076 KB |
testcase_03 | AC | 98 ms
78,252 KB |
testcase_04 | AC | 60 ms
68,832 KB |
testcase_05 | AC | 93 ms
78,672 KB |
testcase_06 | AC | 63 ms
71,088 KB |
testcase_07 | AC | 97 ms
78,720 KB |
testcase_08 | AC | 85 ms
78,460 KB |
testcase_09 | AC | 80 ms
78,092 KB |
testcase_10 | AC | 65 ms
71,700 KB |
testcase_11 | AC | 75 ms
78,128 KB |
testcase_12 | AC | 60 ms
67,232 KB |
testcase_13 | AC | 66 ms
74,468 KB |
testcase_14 | AC | 66 ms
74,352 KB |
testcase_15 | AC | 58 ms
66,956 KB |
コンパイルメッセージ
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')