結果
問題 | No.13 囲みたい! |
ユーザー | Navier_Boltzmann |
提出日時 | 2022-10-10 09:18:37 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 148 ms / 5,000 ms |
コード長 | 1,220 bytes |
コンパイル時間 | 296 ms |
コンパイル使用メモリ | 86,856 KB |
実行使用メモリ | 80,684 KB |
最終ジャッジ日時 | 2023-09-06 10:18:25 |
合計ジャッジ時間 | 3,164 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge14 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 91 ms
72,732 KB |
testcase_01 | AC | 91 ms
72,776 KB |
testcase_02 | AC | 93 ms
72,868 KB |
testcase_03 | AC | 134 ms
78,096 KB |
testcase_04 | AC | 97 ms
77,192 KB |
testcase_05 | AC | 136 ms
80,684 KB |
testcase_06 | AC | 107 ms
78,092 KB |
testcase_07 | AC | 148 ms
80,560 KB |
testcase_08 | AC | 118 ms
79,948 KB |
testcase_09 | AC | 122 ms
80,148 KB |
testcase_10 | AC | 114 ms
78,460 KB |
testcase_11 | AC | 121 ms
79,916 KB |
testcase_12 | AC | 108 ms
78,128 KB |
testcase_13 | AC | 113 ms
78,240 KB |
testcase_14 | AC | 111 ms
78,124 KB |
testcase_15 | AC | 100 ms
72,700 KB |
ソースコード
from collections import * from itertools import * from functools import * from heapq import * import sys,math input = sys.stdin.readline W,H = map(int,input().split()) M = [list(map(int,input().split())) for _ in range(H)] def nb(x,y): tmp = [] if x+1<H: tmp.append((x+1,y)) if x-1>=0: tmp.append((x-1,y)) if y+1<W: tmp.append((x,y+1)) if y-1>=0: tmp.append((x,y-1)) return tmp visited = [[False]*W for _ in range(H)] for i in range(H): for j in range(W): if visited[i][j]: continue visited[i][j] = True m = M[i][j] v = deque() dist = defaultdict(lambda: -1) par = defaultdict(lambda: -1) v.append((i,j)) while v: ix,iy = v.popleft() for jx,jy in nb(ix,iy): if (jx,jy)==par[(ix,iy)]: continue if M[jx][jy] != m: continue par[(jx,jy)]=(ix,iy) if visited[jx][jy]: print('possible') exit() visited[jx][jy] = True v.append((jx,jy)) print('impossible')