結果
問題 | No.2412 YOU Grow Bigger! |
ユーザー | LyricalMaestro |
提出日時 | 2024-12-03 00:04:29 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 1,968 ms / 6,000 ms |
コード長 | 2,241 bytes |
コンパイル時間 | 349 ms |
コンパイル使用メモリ | 82,816 KB |
実行使用メモリ | 86,412 KB |
最終ジャッジ日時 | 2024-12-03 00:04:46 |
合計ジャッジ時間 | 15,071 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 41 ms
54,144 KB |
testcase_01 | AC | 41 ms
53,760 KB |
testcase_02 | AC | 54 ms
63,104 KB |
testcase_03 | AC | 1,901 ms
85,300 KB |
testcase_04 | AC | 1,968 ms
86,412 KB |
testcase_05 | AC | 1,261 ms
82,112 KB |
testcase_06 | AC | 1,621 ms
83,796 KB |
testcase_07 | AC | 1,884 ms
85,540 KB |
testcase_08 | AC | 1,672 ms
83,668 KB |
testcase_09 | AC | 63 ms
70,232 KB |
testcase_10 | AC | 127 ms
76,756 KB |
testcase_11 | AC | 53 ms
64,640 KB |
testcase_12 | AC | 42 ms
54,400 KB |
testcase_13 | AC | 147 ms
76,988 KB |
testcase_14 | AC | 97 ms
77,056 KB |
testcase_15 | AC | 49 ms
61,224 KB |
testcase_16 | AC | 59 ms
67,072 KB |
testcase_17 | AC | 66 ms
71,040 KB |
testcase_18 | AC | 284 ms
77,412 KB |
testcase_19 | AC | 50 ms
60,416 KB |
testcase_20 | AC | 57 ms
65,536 KB |
testcase_21 | AC | 123 ms
76,524 KB |
testcase_22 | AC | 138 ms
77,124 KB |
testcase_23 | AC | 483 ms
77,748 KB |
testcase_24 | AC | 732 ms
79,572 KB |
testcase_25 | AC | 438 ms
77,860 KB |
testcase_26 | AC | 110 ms
76,668 KB |
testcase_27 | AC | 96 ms
76,616 KB |
testcase_28 | AC | 191 ms
77,024 KB |
testcase_29 | AC | 53 ms
61,056 KB |
testcase_30 | AC | 46 ms
54,784 KB |
ソースコード
## https://yukicoder.me/problems/no/2412 from collections import deque def bfs(H, W, cum_s_array): passed = [[False] * (W - 2) for _ in range(H - 2)] passed[0][0] = True queue = deque() queue.append((0, 0)) while len(queue) > 0: h, w = queue.popleft() for dh in range(-1, 2): for dw in range(-1, 2): if dh == 0 and dw == 0: continue new_h = dh + h new_w = dw + w if 0 <= new_h < H - 2 and 0 <= new_w < W - 2: if cum_s_array[new_h + 3][new_w + 3] - cum_s_array[new_h][new_w + 3] - cum_s_array[new_h + 3][new_w] + cum_s_array[new_h][new_w] == 0: if not passed[new_h][new_w]: passed[new_h][new_w] = True queue.append((new_h, new_w)) return passed[-1][-1] def reachable(H, W, s_array): # 累積和計算 cum_s_array = [[0] * (W + 1) for _ in range(H + 1)] for h in range(H): cum_row = 0 for w in range(W): cum_row += s_array[h][w] cum_s_array[h + 1][w + 1] = cum_row + cum_s_array[h][w + 1] # BFSによる探索 return bfs(H, W, cum_s_array) def main(): H, W = map(int, input().split()) S = [] for _ in range(H): S.append(input()) # 迷路のベースを作成 s_array = [] for s in S: row = [] for i in range(len(s)): if s[i] == "#": row.append(1) else: row.append(0) s_array.append(row) if not reachable(H, W, s_array): print(0) return def forbidden(h, w): if 0 <= h < 3 and 0 <= w < 3: return True if H - 3 <= h < H and W - 3 <= w < W: return True return False for h in range(H): for w in range(W): if S[h][w] == ".": if not forbidden(h, w): s_array[h][w] = 1 if not reachable(H, W, s_array): print(1) return s_array[h][w] = 0 print(2) if __name__ == '__main__': main()