結果

問題 No.13 囲みたい!
ユーザー sotanishysotanishy
提出日時 2021-03-16 22:02:57
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 84 ms / 5,000 ms
コード長 787 bytes
コンパイル時間 209 ms
コンパイル使用メモリ 82,424 KB
実行使用メモリ 76,416 KB
最終ジャッジ日時 2024-04-26 04:19:50
合計ジャッジ時間 1,865 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
51,968 KB
testcase_01 AC 38 ms
52,480 KB
testcase_02 AC 38 ms
52,736 KB
testcase_03 AC 53 ms
65,896 KB
testcase_04 AC 43 ms
59,264 KB
testcase_05 AC 61 ms
68,736 KB
testcase_06 AC 52 ms
64,640 KB
testcase_07 AC 84 ms
76,416 KB
testcase_08 AC 55 ms
66,816 KB
testcase_09 AC 54 ms
66,432 KB
testcase_10 AC 52 ms
63,488 KB
testcase_11 AC 49 ms
63,616 KB
testcase_12 AC 47 ms
60,416 KB
testcase_13 AC 49 ms
63,292 KB
testcase_14 AC 54 ms
64,128 KB
testcase_15 AC 38 ms
52,352 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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')
0