結果

問題 No.13 囲みたい!
ユーザー dangodango
提出日時 2023-07-08 09:29:12
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 1,089 bytes
コンパイル時間 269 ms
コンパイル使用メモリ 87,124 KB
実行使用メモリ 82,380 KB
最終ジャッジ日時 2023-09-29 10:45:32
合計ジャッジ時間 2,883 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 70 ms
71,508 KB
testcase_01 AC 69 ms
71,384 KB
testcase_02 AC 69 ms
71,260 KB
testcase_03 RE -
testcase_04 AC 77 ms
76,348 KB
testcase_05 RE -
testcase_06 AC 83 ms
76,776 KB
testcase_07 AC 102 ms
78,016 KB
testcase_08 AC 91 ms
77,168 KB
testcase_09 AC 89 ms
76,964 KB
testcase_10 AC 85 ms
76,856 KB
testcase_11 AC 89 ms
77,072 KB
testcase_12 AC 79 ms
75,716 KB
testcase_13 AC 88 ms
76,864 KB
testcase_14 AC 96 ms
78,308 KB
testcase_15 AC 72 ms
71,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def POS(i, j, w):
    return i * (w + 2) + j
def dfs(x, y, dir, number, board, w, h):
    dx = [1, 0, -1, 0]
    dy = [0, 1, 0, -1]
    board[POS(x, y, w)] = -number
    for k in range(4):
        if dir == k:
            continue
        nx = x + dx[k]
        ny = y + dy[k]
        if board[POS(nx, ny, w)] == -number:
            return 1
        if board[POS(nx, ny, w)] == number:
            t = dfs(nx, ny, (k + 2) % 4, number, board, w, h)
            if t == 1:
                return 1
    return 0
def main():
    w, h = map(int,input().split())
    board = [0] * ((w + 2) * (h + 2))
    for i in range(1, h + 1):
        row = list(map(int, input().split()))
        for j in range(1, w + 1):
            board[POS(i, j, w)] = row[j - 1]
    for i in range(1,h + 1):
        for j in range(1,w + 1):
            if board[POS(i, j, w)] > 0:
                res = dfs(i, j, 4, board[POS(i, j, w)], board, w, h)
                if res == 1:
                    print("possible")
                    exit(0)
    print("impossible")
    return
if __name__ == "__main__":
    main()
0