結果
| 問題 |
No.13 囲みたい!
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2023-01-22 19:43:04 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 81 ms / 5,000 ms |
| コード長 | 1,431 bytes |
| コンパイル時間 | 238 ms |
| コンパイル使用メモリ | 82,304 KB |
| 実行使用メモリ | 77,056 KB |
| 最終ジャッジ日時 | 2024-06-24 23:01:44 |
| 合計ジャッジ時間 | 1,975 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 16 |
ソースコード
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)]
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
if y!=0:
if M[y-1][x]==M[y][x]:
if visit[y-1][x]:
cnt+=1
else:
visit[y-1][x]=1
Q.append((y-1,x))
if y!=h-1:
if M[y+1][x]==M[y][x]:
if visit[y+1][x]:
cnt+=1
else:
visit[y+1][x]=1
Q.append((y+1,x))
if x!=0:
if M[y][x-1]==M[y][x]:
if visit[y][x-1]:
cnt+=1
else:
visit[y][x-1]=1
Q.append((y,x-1))
if x!=w-1:
if M[y][x+1]==M[y][x]:
if visit[y][x+1]:
cnt+=1
else:
visit[y][x+1]=1
Q.append((y,x+1))
if cnt>=2:
print("possible")
exit()
print("impossible")