結果

問題 No.13 囲みたい!
ユーザー 👑 colognecologne
提出日時 2022-01-20 17:57:59
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 844 bytes
コンパイル時間 174 ms
コンパイル使用メモリ 81,920 KB
実行使用メモリ 81,024 KB
最終ジャッジ日時 2024-05-03 03:44:16
合計ジャッジ時間 2,062 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
51,840 KB
testcase_01 AC 40 ms
52,224 KB
testcase_02 AC 39 ms
51,968 KB
testcase_03 RE -
testcase_04 AC 44 ms
59,648 KB
testcase_05 RE -
testcase_06 AC 52 ms
62,336 KB
testcase_07 AC 74 ms
76,364 KB
testcase_08 AC 57 ms
73,856 KB
testcase_09 AC 58 ms
73,728 KB
testcase_10 AC 53 ms
63,616 KB
testcase_11 AC 57 ms
70,912 KB
testcase_12 AC 46 ms
59,392 KB
testcase_13 AC 54 ms
65,920 KB
testcase_14 AC 54 ms
65,920 KB
testcase_15 AC 39 ms
52,608 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