結果

問題 No.13 囲みたい!
ユーザー 👑 colognecologne
提出日時 2022-01-20 17:57:59
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 844 bytes
コンパイル時間 394 ms
コンパイル使用メモリ 87,048 KB
実行使用メモリ 85,448 KB
最終ジャッジ日時 2023-08-15 16:43:58
合計ジャッジ時間 2,760 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 60 ms
71,340 KB
testcase_01 AC 61 ms
71,136 KB
testcase_02 AC 61 ms
71,260 KB
testcase_03 RE -
testcase_04 AC 65 ms
75,836 KB
testcase_05 RE -
testcase_06 AC 74 ms
76,216 KB
testcase_07 AC 92 ms
83,468 KB
testcase_08 AC 77 ms
77,072 KB
testcase_09 AC 76 ms
77,008 KB
testcase_10 AC 72 ms
76,084 KB
testcase_11 AC 72 ms
76,372 KB
testcase_12 AC 67 ms
75,340 KB
testcase_13 AC 72 ms
76,088 KB
testcase_14 AC 73 ms
76,380 KB
testcase_15 AC 60 ms
71,244 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

input = sys.stdin.readline


def main():
    W, H = map(int, input().split())
    A = [list(map(int, input().split())) for i in range(H)]

    vis = [[False]*W for i in range(H)]

    def dfs(cx, cy, px, py):
        if vis[cx][cy]:
            return True
        vis[cx][cy] = True
        for dx, dy in [(0, -1), (0, 1), (-1, 0), (1, 0)]:
            nx, ny = cx + dx, cy + dy
            if nx == px and ny == py:
                continue
            if 0 <= nx < H and 0 <= ny < W and A[nx][ny] == A[cx][cy]:
                if dfs(nx, ny, cx, cy):
                    return True

        return False

    for i in range(H):
        for j in range(W):
            if not vis[i][j] and dfs(i, j, -1, -1):
                print('possible')
                return
    print('impossible')


if __name__ == '__main__':
    main()
0