結果

問題 No.13 囲みたい!
ユーザー taisuketaisuke
提出日時 2023-03-02 15:22:35
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
RE  
実行時間 -
コード長 879 bytes
コンパイル時間 249 ms
コンパイル使用メモリ 11,872 KB
実行使用メモリ 10,980 KB
最終ジャッジ日時 2023-10-17 12:13:05
合計ジャッジ時間 1,903 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 30 ms
10,040 KB
testcase_01 AC 29 ms
10,044 KB
testcase_02 AC 30 ms
10,040 KB
testcase_03 RE -
testcase_04 AC 33 ms
10,416 KB
testcase_05 RE -
testcase_06 AC 34 ms
10,520 KB
testcase_07 AC 48 ms
10,364 KB
testcase_08 AC 48 ms
10,544 KB
testcase_09 AC 48 ms
10,544 KB
testcase_10 AC 33 ms
10,140 KB
testcase_11 AC 44 ms
10,400 KB
testcase_12 AC 31 ms
10,088 KB
testcase_13 AC 35 ms
10,216 KB
testcase_14 AC 37 ms
10,232 KB
testcase_15 AC 30 ms
10,072 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

w, h = map(int, input().split())
a = [[*map(int, input().split())] for _ in range(h)]

INF = 10**9

visit = [[False for i in range(w)] for j in range(h)]
dist = [[INF for i in range(w)] for j in range(h)]
dy = [-1, 0, 1, 0]
dx = [0, 1, 0, -1]


def dfs(now, pre, num):
    d = dist[now[0]][now[1]]
    for i in range(4):
        y2 = now[0] + dy[i]
        x2 = now[1] + dx[i]
        if y2 < 0 or y2 > h-1 or x2 < 0 or x2 > w-1:
            continue
        if not a[y2][x2] == num or (y2 == pre[0] and x2 == pre[1]):
            continue

        if dist[y2][x2] == INF:
            dist[y2][x2] = d + 1
            dfs([y2, x2], now, num)
        elif d >= 3:
            print("possible")
            exit(0)


for i in range(h):
    for j in range(w):
        if dist[i][j] == INF:
            dist[i][j] = 0
            dfs([i, j], [-1, -1], a[i][j])


print("impossible")
0