結果
問題 | No.13 囲みたい! |
ユーザー | sotanishy |
提出日時 | 2021-03-16 22:02:57 |
言語 | PyPy3 (7.3.13) |
結果 |
AC
|
実行時間 | 114 ms / 5,000 ms |
コード長 | 787 bytes |
コンパイル時間 | 388 ms |
コンパイル使用メモリ | 87,000 KB |
実行使用メモリ | 77,388 KB |
最終ジャッジ日時 | 2023-08-08 11:18:23 |
合計ジャッジ時間 | 3,038 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge11 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 75 ms
71,360 KB |
testcase_01 | AC | 74 ms
71,264 KB |
testcase_02 | AC | 79 ms
71,288 KB |
testcase_03 | AC | 88 ms
76,548 KB |
testcase_04 | AC | 77 ms
75,748 KB |
testcase_05 | AC | 96 ms
76,344 KB |
testcase_06 | AC | 90 ms
76,304 KB |
testcase_07 | AC | 114 ms
77,388 KB |
testcase_08 | AC | 90 ms
76,692 KB |
testcase_09 | AC | 87 ms
76,580 KB |
testcase_10 | AC | 88 ms
76,504 KB |
testcase_11 | AC | 86 ms
76,448 KB |
testcase_12 | AC | 80 ms
76,060 KB |
testcase_13 | AC | 86 ms
76,508 KB |
testcase_14 | AC | 89 ms
76,352 KB |
testcase_15 | AC | 76 ms
71,368 KB |
ソースコード
import sys input = sys.stdin.readline W, H = map(int, input().split()) M = [list(map(int, input().split())) for _ in range(H)] used = [[False] * W for _ in range(H)] for si in range(H): for sj in range(W): if used[si][sj]: continue st = [(si, sj, -1, -1)] used[si][sj] = True while st: i, j, pi, pj = st.pop() for di, dj in [(1, 0), (0, 1), (-1, 0), (0, -1)]: ni, nj = i + di, j + dj if 0 <= ni < H and 0 <= nj < W and M[ni][nj] == M[i][j] and (ni, nj) != (pi, pj): if used[ni][nj]: print('possible') exit() st.append((ni, nj, i, j)) used[ni][nj] = True print('impossible')