結果

問題 No.13 囲みたい!
ユーザー HydruHydru
提出日時 2023-01-22 19:52:05
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 134 ms / 5,000 ms
コード長 886 bytes
コンパイル時間 277 ms
コンパイル使用メモリ 87,088 KB
実行使用メモリ 78,588 KB
最終ジャッジ日時 2023-09-07 04:32:24
合計ジャッジ時間 3,115 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 92 ms
71,524 KB
testcase_01 AC 92 ms
71,320 KB
testcase_02 AC 94 ms
71,596 KB
testcase_03 AC 115 ms
77,756 KB
testcase_04 AC 99 ms
77,112 KB
testcase_05 AC 118 ms
77,844 KB
testcase_06 AC 108 ms
77,924 KB
testcase_07 AC 134 ms
78,588 KB
testcase_08 AC 116 ms
77,864 KB
testcase_09 AC 117 ms
77,848 KB
testcase_10 AC 111 ms
77,864 KB
testcase_11 AC 106 ms
78,052 KB
testcase_12 AC 104 ms
77,360 KB
testcase_13 AC 108 ms
77,564 KB
testcase_14 AC 115 ms
77,752 KB
testcase_15 AC 93 ms
71,480 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque

w,h=map(int,input().split())

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

visit=[[0 for _ in range(w)] for _ in range(h)]

vx=[0,1,0,-1]
vy=[1,0,-1,0]

for i in range(h):
    for j in range(w):
        if visit[i][j]:
            continue
        Q=deque()
        visit[i][j]=1
        Q.append((i,j))
        while(Q):
            y,x=Q.pop()
            cnt=0
            for k in range(4):
                ny=y+vy[k]
                nx=x+vx[k]
                if 0<=ny<len(M) and 0<=nx<len(M[0]):
                    if M[ny][nx]==M[y][x]:
                        if visit[ny][nx]:
                            cnt+=1
                        else:
                            visit[ny][nx]=1
                            Q.append((ny,nx))
            if cnt>=2:
                print("possible")
                exit()
    
print("impossible")
0