結果

問題 No.13 囲みたい!
ユーザー tnodinotnodino
提出日時 2022-02-02 22:19:50
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 31 ms / 5,000 ms
コード長 818 bytes
コンパイル時間 95 ms
コンパイル使用メモリ 11,056 KB
実行使用メモリ 10,160 KB
最終ジャッジ日時 2023-09-02 03:00:01
合計ジャッジ時間 1,515 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
8,296 KB
testcase_01 AC 16 ms
8,200 KB
testcase_02 AC 16 ms
7,916 KB
testcase_03 AC 31 ms
10,160 KB
testcase_04 AC 20 ms
8,636 KB
testcase_05 AC 31 ms
9,576 KB
testcase_06 AC 19 ms
8,748 KB
testcase_07 AC 29 ms
8,644 KB
testcase_08 AC 30 ms
8,584 KB
testcase_09 AC 30 ms
8,676 KB
testcase_10 AC 18 ms
8,224 KB
testcase_11 AC 27 ms
8,572 KB
testcase_12 AC 17 ms
7,836 KB
testcase_13 AC 20 ms
8,348 KB
testcase_14 AC 21 ms
8,480 KB
testcase_15 AC 16 ms
7,816 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from sys import setrecursionlimit
setrecursionlimit(10**6)

def dfs(x, y, rx, ry):
    flg[x][y] = False
    Check[x][y] = False
    for i in range(4):
        nx,my = x+dx[i],y+dy[i]
        if nx < 0 or H <= nx or my < 0 or W <= my:
            continue
        if nx == rx and my == ry:
            continue
        if M[x][y] == M[nx][my]:
            if flg[nx][my]:
                dfs(nx, my, x, y)
            else:
                print('possible')
                exit()
    flg[x][y] = True

W,H = map(int,input().split())
M = [list(map(int,input().split())) for _ in range(H)]
flg = [[True] * W for _ in range(H)]
Check = [[True] * W for _ in range(H)]
dx = [-1, 1, 0, 0]
dy = [0, 0, -1, 1]
for i in range(H):
    for j in range(W):
        if Check[i][j]:
            dfs(i, j, -1, -1)
print('impossible')
0