結果
問題 | No.2412 YOU Grow Bigger! |
ユーザー | LyricalMaestro |
提出日時 | 2024-12-03 00:03:33 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,134 bytes |
コンパイル時間 | 296 ms |
コンパイル使用メモリ | 82,304 KB |
実行使用メモリ | 81,920 KB |
最終ジャッジ日時 | 2024-12-03 00:03:43 |
合計ジャッジ時間 | 9,700 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 42 ms
54,144 KB |
testcase_01 | AC | 41 ms
54,016 KB |
testcase_02 | AC | 45 ms
55,040 KB |
testcase_03 | AC | 1,051 ms
81,280 KB |
testcase_04 | AC | 1,118 ms
81,920 KB |
testcase_05 | AC | 688 ms
79,952 KB |
testcase_06 | AC | 939 ms
80,640 KB |
testcase_07 | AC | 1,052 ms
81,444 KB |
testcase_08 | AC | 993 ms
80,640 KB |
testcase_09 | AC | 59 ms
66,304 KB |
testcase_10 | AC | 88 ms
76,416 KB |
testcase_11 | AC | 47 ms
60,800 KB |
testcase_12 | AC | 41 ms
54,528 KB |
testcase_13 | AC | 102 ms
76,416 KB |
testcase_14 | AC | 55 ms
64,512 KB |
testcase_15 | AC | 47 ms
61,312 KB |
testcase_16 | AC | 53 ms
63,616 KB |
testcase_17 | AC | 56 ms
65,536 KB |
testcase_18 | AC | 210 ms
76,736 KB |
testcase_19 | AC | 45 ms
60,800 KB |
testcase_20 | AC | 48 ms
61,696 KB |
testcase_21 | WA | - |
testcase_22 | AC | 95 ms
76,544 KB |
testcase_23 | AC | 173 ms
76,800 KB |
testcase_24 | AC | 426 ms
77,644 KB |
testcase_25 | WA | - |
testcase_26 | AC | 82 ms
76,800 KB |
testcase_27 | AC | 74 ms
76,544 KB |
testcase_28 | AC | 124 ms
76,672 KB |
testcase_29 | AC | 48 ms
60,672 KB |
testcase_30 | AC | 42 ms
54,272 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, dw in ((1, 0), (-1, 0), (0, 1), (0, -1)): 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()