結果
問題 | No.2412 YOU Grow Bigger! |
ユーザー | hari64 |
提出日時 | 2023-07-19 22:42:19 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 4,257 ms / 6,000 ms |
コード長 | 2,393 bytes |
コンパイル時間 | 146 ms |
コンパイル使用メモリ | 82,304 KB |
実行使用メモリ | 265,516 KB |
最終ジャッジ日時 | 2024-11-21 08:42:36 |
合計ジャッジ時間 | 35,335 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 65 ms
68,392 KB |
testcase_01 | AC | 45 ms
54,728 KB |
testcase_02 | AC | 59 ms
66,444 KB |
testcase_03 | AC | 4,257 ms
265,028 KB |
testcase_04 | AC | 3,936 ms
265,516 KB |
testcase_05 | AC | 2,612 ms
185,344 KB |
testcase_06 | AC | 3,073 ms
219,672 KB |
testcase_07 | AC | 3,956 ms
264,708 KB |
testcase_08 | AC | 2,961 ms
216,552 KB |
testcase_09 | AC | 93 ms
77,440 KB |
testcase_10 | AC | 1,092 ms
100,092 KB |
testcase_11 | AC | 64 ms
68,352 KB |
testcase_12 | AC | 49 ms
60,160 KB |
testcase_13 | AC | 1,482 ms
119,876 KB |
testcase_14 | AC | 995 ms
97,944 KB |
testcase_15 | AC | 103 ms
76,416 KB |
testcase_16 | AC | 92 ms
76,928 KB |
testcase_17 | AC | 91 ms
76,800 KB |
testcase_18 | AC | 1,095 ms
101,476 KB |
testcase_19 | AC | 75 ms
74,112 KB |
testcase_20 | AC | 68 ms
70,272 KB |
testcase_21 | AC | 507 ms
82,372 KB |
testcase_22 | AC | 1,394 ms
106,776 KB |
testcase_23 | AC | 799 ms
91,704 KB |
testcase_24 | AC | 1,621 ms
127,648 KB |
testcase_25 | AC | 712 ms
88,676 KB |
testcase_26 | AC | 816 ms
91,268 KB |
testcase_27 | AC | 678 ms
84,592 KB |
testcase_28 | AC | 1,178 ms
103,136 KB |
testcase_29 | AC | 89 ms
76,736 KB |
testcase_30 | AC | 57 ms
64,896 KB |
ソースコード
from collections import deque def canReach(H, W, Ss): grid = [[False for _ in range(W - 2)] for _ in range(H - 2)] for h in range(1, H - 1): for w in range(1, W - 1): grid[h - 1][w - 1] = True for dh in range(-1, 2): for dw in range(-1, 2): if Ss[h + dh][w + dw] == "#": grid[h - 1][w - 1] = False # 0,0からH-3,W-3までの経路があるか adj = [[[] for _ in range(W - 2)] for _ in range(H - 2)] for h in range(H - 2): for w in range(W - 2): if not grid[h][w]: continue for dh in range(-1, 2): for dw in range(-1, 2): if dh == 0 and dw == 0: continue if ( 0 <= h + dh < H - 2 and 0 <= w + dw < W - 2 and grid[h + dh][w + dw] ): adj[h][w].append((h + dh, w + dw)) q = deque([(0, 0)]) visited = [[False for _ in range(W - 2)] for _ in range(H - 2)] visited[0][0] = True while q: h, w = q.popleft() for nh, nw in adj[h][w]: if not visited[nh][nw]: visited[nh][nw] = True q.append((nh, nw)) return visited[H - 3][W - 3] def main(): H, W = map(int, input().split()) assert 6 <= H <= 500 assert 6 <= W <= 500 Ss = [] for _ in range(H): S = input().strip() assert len(S) == W for c in S: assert c == "." or c == "#" Ss.append(S) for i in range(3): for j in range(3): assert Ss[i][j] == "." for i in range(H - 3, H): for j in range(W - 3, W): assert Ss[i][j] == "." ans = 2 if not canReach(H, W, Ss): ans = 0 else: for h in range(H): for w in range(W): if h < 3 and w < 3: continue if h >= H - 3 and w >= W - 3: continue if Ss[h][w] == "#": continue Ss[h] = Ss[h][:w] + "#" + Ss[h][w + 1 :] if not canReach(H, W, Ss): ans = 1 Ss[h] = Ss[h][:w] + "." + Ss[h][w + 1 :] print(ans) if __name__ == "__main__": main()