結果
問題 | No.2412 YOU Grow Bigger! |
ユーザー | mkawa2 |
提出日時 | 2023-08-11 22:57:16 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,475 bytes |
コンパイル時間 | 334 ms |
コンパイル使用メモリ | 82,364 KB |
実行使用メモリ | 69,888 KB |
最終ジャッジ日時 | 2024-11-18 18:10:19 |
合計ジャッジ時間 | 3,252 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 46 ms
56,068 KB |
testcase_01 | AC | 46 ms
55,116 KB |
testcase_02 | AC | 43 ms
54,164 KB |
testcase_03 | AC | 49 ms
60,700 KB |
testcase_04 | AC | 47 ms
63,204 KB |
testcase_05 | AC | 52 ms
65,512 KB |
testcase_06 | AC | 48 ms
60,948 KB |
testcase_07 | AC | 46 ms
61,416 KB |
testcase_08 | AC | 57 ms
67,776 KB |
testcase_09 | AC | 63 ms
69,308 KB |
testcase_10 | AC | 54 ms
65,364 KB |
testcase_11 | AC | 55 ms
65,048 KB |
testcase_12 | AC | 49 ms
62,680 KB |
testcase_13 | AC | 57 ms
66,504 KB |
testcase_14 | WA | - |
testcase_15 | AC | 65 ms
68,828 KB |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | AC | 63 ms
68,896 KB |
testcase_19 | AC | 59 ms
67,188 KB |
testcase_20 | WA | - |
testcase_21 | AC | 60 ms
66,708 KB |
testcase_22 | WA | - |
testcase_23 | WA | - |
testcase_24 | WA | - |
testcase_25 | AC | 58 ms
65,052 KB |
testcase_26 | AC | 59 ms
67,204 KB |
testcase_27 | WA | - |
testcase_28 | AC | 59 ms
68,416 KB |
testcase_29 | WA | - |
testcase_30 | WA | - |
ソースコード
import sys # sys.setrecursionlimit(200005) # sys.set_int_max_str_digits(1000005) int1 = lambda x: int(x)-1 pDB = lambda *x: print(*x, end="\n", file=sys.stderr) p2D = lambda x: print(*x, sep="\n", end="\n\n", file=sys.stderr) def II(): return int(sys.stdin.readline()) def LI(): return list(map(int, sys.stdin.readline().split())) def LLI(rows_number): return [LI() for _ in range(rows_number)] def LI1(): return list(map(int1, sys.stdin.readline().split())) def LLI1(rows_number): return [LI1() for _ in range(rows_number)] def SI(): return sys.stdin.readline().rstrip() # dij = [(0, 1), (-1, 0), (0, -1), (1, 0)] dij = [(0, 1), (-1, 0), (0, -1), (1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)] inf = -1-(-1 << 63) # md = 10**9+7 md = 998244353 from collections import deque h, w = LI() ss = [[(c == "#")*1 for c in SI()] for _ in range(h)] for i in range(h): for j in range(w): if ss[i][j] == 1: for di, dj in dij: ni, nj = i+di, j+dj if ni < 0 or nj < 0 or ni >= h or nj >= w: continue if ss[ni][nj] == 0: ss[ni][nj] = 2 # p2D(ss) q = deque() dist = [[inf]*w for _ in range(h)] for j in range(w): if ss[0][j]: q.append((0, j)) dist[0][j] = 0 for i in range(h): if ss[i][w-1]: q.append((i, w-1)) dist[i][w-1] = 0 while q: i, j = q.popleft() d = dist[i][j] for di, dj in dij: ni, nj = i+di, j+dj if ni < 0 or nj < 0 or ni >= h or nj >= w: continue if dist[ni][nj] == inf: if d == 0 and ss[ni][nj]: dist[ni][nj] = 0 q.appendleft((ni,nj)) else: dist[ni][nj] = d+1 q.append((ni, nj)) st = [] for i in range(h): if ss[i][0]: if dist[i][0] == 0: print(0) exit() if dist[i][0] < 5: print(1) exit() st.append((i, 0)) for j in range(w): if ss[h-1][j]: if dist[h-1][j] == 0: print(0) exit() if dist[h-1][j] < 5: print(1) exit() st.append((h-1, j)) while st: i, j = st.pop() for di, dj in dij: ni, nj = i+di, j+dj if ni < 0 or nj < 0 or ni >= h or nj >= w: continue if ss[ni][nj] and dist[ni][nj] != inf: if dist[ni][nj] < 5: print(1) exit() dist[ni][nj] = inf st.append((ni, nj)) print(2)