結果

問題 No.13 囲みたい!
ユーザー ああいいああいい
提出日時 2022-03-02 20:42:33
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 108 ms / 5,000 ms
コード長 836 bytes
コンパイル時間 740 ms
コンパイル使用メモリ 86,900 KB
実行使用メモリ 77,092 KB
最終ジャッジ日時 2023-09-23 11:45:50
合計ジャッジ時間 3,680 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 70 ms
71,180 KB
testcase_01 AC 69 ms
71,452 KB
testcase_02 AC 69 ms
71,312 KB
testcase_03 AC 85 ms
76,588 KB
testcase_04 AC 74 ms
75,816 KB
testcase_05 AC 91 ms
76,748 KB
testcase_06 AC 85 ms
76,548 KB
testcase_07 AC 108 ms
77,092 KB
testcase_08 AC 86 ms
76,520 KB
testcase_09 AC 88 ms
76,460 KB
testcase_10 AC 86 ms
76,500 KB
testcase_11 AC 81 ms
76,468 KB
testcase_12 AC 77 ms
75,920 KB
testcase_13 AC 83 ms
76,308 KB
testcase_14 AC 86 ms
76,484 KB
testcase_15 AC 72 ms
71,212 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

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

memo = [[0] * W for _ in range(H)]
import sys
for h in range(H):
    for w in range(W):
        if memo[h][w] == 1:continue
        stack = [(h,w,-1,-1)]
        memo[h][w] = 1
        while stack:
            h,w,bh,bw = stack.pop()
            for i,j in [(1,0),(-1,0),(0,1),(0,-1)]:
                if 0 <= h + i < H and 0 <= w + j < W:
                    if h + i != bh or w + j != bw:
                        if S[h+i][w+j] == S[h][w]:
                            if memo[h+i][w+j] == 1:
                                print("possible")
                                exit()
                            else:
                                stack.append((h+i,w+j,h,w))
                                memo[h+i][w+j] = 1
print("impossible")
0