結果

問題 No.13 囲みたい!
ユーザー szkhtsszkhts
提出日時 2022-06-19 09:37:47
言語 Python3
(3.11.6 + numpy 1.26.0 + scipy 1.11.3)
結果
RE  
実行時間 -
コード長 866 bytes
コンパイル時間 69 ms
コンパイル使用メモリ 11,004 KB
実行使用メモリ 9,240 KB
最終ジャッジ日時 2023-08-01 14:42:57
合計ジャッジ時間 1,188 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 15 ms
7,908 KB
testcase_01 AC 15 ms
7,840 KB
testcase_02 AC 14 ms
7,984 KB
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 AC 35 ms
8,592 KB
testcase_07 AC 34 ms
8,508 KB
testcase_08 AC 34 ms
8,672 KB
testcase_09 AC 34 ms
8,640 KB
testcase_10 AC 18 ms
8,200 KB
testcase_11 AC 29 ms
8,416 KB
testcase_12 AC 17 ms
8,184 KB
testcase_13 AC 21 ms
8,508 KB
testcase_14 AC 21 ms
8,480 KB
testcase_15 AC 15 ms
7,804 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

W, H = map(int, input().split())

field = []
for _ in range(H):
    field.append(list(map(int, input().split())))

def ok(x, y):
    return y >= 0 and x >= 0 and x < H and y < W

def dfs(x, y):
    dx = [1, 0, -1, 0]
    dy = [0, 1, 0, -1]
    visit[x][y] = True
    c = (1, 0)

    for k in range(4):
        ny = y + dy[k]
        nx = x + dx[k]
        if ok(nx, ny) and field[nx][ny] == field[x][y]:
            if not visit[nx][ny]:
                res = dfs(nx, ny)
                c = (c[0] + res[0], c[1] + res[1])
            c = (c[0], c[1] + 1)

    return c

visit = [[False for _ in range(W)] for _ in range(H)]
ans = False

for i in range(H):
    for j in range(W):
        if not visit[i][j]:
            res = dfs(i, j)
            if res[1] // 2 != res[0] - 1:
                ans = True

if ans:
    print("possible")
else:
    print("impossible")
0