結果
問題 | No.871 かえるのうた |
ユーザー | 双六 |
提出日時 | 2020-08-27 18:23:46 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 311 ms / 2,000 ms |
コード長 | 1,216 bytes |
コンパイル時間 | 360 ms |
コンパイル使用メモリ | 87,052 KB |
実行使用メモリ | 117,316 KB |
最終ジャッジ日時 | 2023-08-20 09:36:57 |
合計ジャッジ時間 | 10,895 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge12 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 93 ms
71,712 KB |
testcase_01 | AC | 94 ms
71,588 KB |
testcase_02 | AC | 94 ms
71,528 KB |
testcase_03 | AC | 96 ms
71,364 KB |
testcase_04 | AC | 96 ms
71,216 KB |
testcase_05 | AC | 96 ms
71,692 KB |
testcase_06 | AC | 97 ms
71,572 KB |
testcase_07 | AC | 98 ms
71,700 KB |
testcase_08 | AC | 132 ms
78,452 KB |
testcase_09 | AC | 129 ms
78,472 KB |
testcase_10 | AC | 116 ms
77,620 KB |
testcase_11 | AC | 120 ms
77,824 KB |
testcase_12 | AC | 157 ms
85,132 KB |
testcase_13 | AC | 138 ms
79,300 KB |
testcase_14 | AC | 238 ms
109,600 KB |
testcase_15 | AC | 239 ms
114,396 KB |
testcase_16 | AC | 311 ms
111,920 KB |
testcase_17 | AC | 235 ms
111,188 KB |
testcase_18 | AC | 154 ms
86,128 KB |
testcase_19 | AC | 251 ms
114,216 KB |
testcase_20 | AC | 131 ms
79,960 KB |
testcase_21 | AC | 184 ms
95,400 KB |
testcase_22 | AC | 95 ms
71,668 KB |
testcase_23 | AC | 95 ms
71,340 KB |
testcase_24 | AC | 91 ms
71,296 KB |
testcase_25 | AC | 133 ms
78,896 KB |
testcase_26 | AC | 148 ms
80,300 KB |
testcase_27 | AC | 141 ms
82,272 KB |
testcase_28 | AC | 94 ms
71,688 KB |
testcase_29 | AC | 206 ms
112,220 KB |
testcase_30 | AC | 237 ms
116,456 KB |
testcase_31 | AC | 129 ms
78,452 KB |
testcase_32 | AC | 223 ms
113,052 KB |
testcase_33 | AC | 244 ms
114,336 KB |
testcase_34 | AC | 161 ms
89,072 KB |
testcase_35 | AC | 205 ms
109,032 KB |
testcase_36 | AC | 225 ms
117,316 KB |
testcase_37 | AC | 194 ms
97,804 KB |
testcase_38 | AC | 270 ms
112,668 KB |
testcase_39 | AC | 249 ms
113,436 KB |
testcase_40 | AC | 219 ms
113,768 KB |
testcase_41 | AC | 96 ms
71,604 KB |
testcase_42 | AC | 216 ms
113,836 KB |
testcase_43 | AC | 97 ms
71,744 KB |
testcase_44 | AC | 94 ms
71,884 KB |
testcase_45 | AC | 125 ms
78,564 KB |
testcase_46 | AC | 93 ms
71,960 KB |
testcase_47 | AC | 94 ms
71,708 KB |
testcase_48 | AC | 94 ms
71,372 KB |
ソースコード
import sys; input = sys.stdin.buffer.readline sys.setrecursionlimit(10**7) from collections import defaultdict con = 10 ** 9 + 7; INF = float("inf") from collections import deque import bisect def getlist(): return list(map(int, input().split())) class Graph(object): def __init__(self): self.graph = defaultdict(list) def __len__(self): return len(self.graph) def add_edge(self, a, b): self.graph[a].append(b) class BFS(object): def __init__(self, graph, s, N): self.g = graph.graph self.Q = deque(); self.Q.append(s) self.dist = [INF] * N; self.dist[s] = 0 while self.Q: v = self.Q.popleft() for i in self.g[v]: if self.dist[i] == INF: self.dist[i] = self.dist[v] + 1 self.Q.append(i) #処理内容 def main(): N, K = getlist() X = getlist() A = getlist() G = Graph() for i in range(K - 1): G.add_edge(i, i + 1) for i in range(K - 1, N): G.add_edge(i + 1, i) for i in range(N): left = bisect.bisect_left(X, X[i] - A[i]) right = bisect.bisect_right(X, X[i] + A[i]) - 1 G.add_edge(i, left) G.add_edge(i, right) BF = BFS(G, K - 1, N) ans = 0 for i in range(N): if BF.dist[i] != INF: ans += 1 print(ans) if __name__ == '__main__': main()