結果
問題 | No.871 かえるのうた |
ユーザー | Theta |
提出日時 | 2022-11-25 14:46:16 |
言語 | Python3 (3.12.2 + numpy 1.26.4 + scipy 1.12.0) |
結果 |
AC
|
実行時間 | 246 ms / 2,000 ms |
コード長 | 1,532 bytes |
コンパイル時間 | 303 ms |
コンパイル使用メモリ | 12,800 KB |
実行使用メモリ | 29,872 KB |
最終ジャッジ日時 | 2024-05-07 16:48:53 |
合計ジャッジ時間 | 6,078 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 41 ms
11,776 KB |
testcase_01 | AC | 35 ms
11,520 KB |
testcase_02 | AC | 35 ms
11,648 KB |
testcase_03 | AC | 34 ms
11,648 KB |
testcase_04 | AC | 34 ms
11,520 KB |
testcase_05 | AC | 34 ms
11,648 KB |
testcase_06 | AC | 35 ms
11,648 KB |
testcase_07 | AC | 33 ms
11,520 KB |
testcase_08 | AC | 36 ms
12,160 KB |
testcase_09 | AC | 38 ms
12,160 KB |
testcase_10 | AC | 34 ms
11,776 KB |
testcase_11 | AC | 34 ms
11,904 KB |
testcase_12 | AC | 55 ms
14,720 KB |
testcase_13 | AC | 39 ms
12,416 KB |
testcase_14 | AC | 166 ms
29,360 KB |
testcase_15 | AC | 163 ms
28,808 KB |
testcase_16 | AC | 246 ms
29,872 KB |
testcase_17 | AC | 160 ms
26,308 KB |
testcase_18 | AC | 58 ms
13,924 KB |
testcase_19 | AC | 173 ms
27,836 KB |
testcase_20 | AC | 51 ms
12,928 KB |
testcase_21 | AC | 94 ms
17,596 KB |
testcase_22 | AC | 37 ms
11,648 KB |
testcase_23 | AC | 37 ms
11,520 KB |
testcase_24 | AC | 36 ms
11,520 KB |
testcase_25 | AC | 40 ms
12,032 KB |
testcase_26 | AC | 56 ms
13,056 KB |
testcase_27 | AC | 52 ms
14,080 KB |
testcase_28 | AC | 35 ms
11,648 KB |
testcase_29 | AC | 103 ms
19,728 KB |
testcase_30 | AC | 192 ms
23,784 KB |
testcase_31 | AC | 39 ms
12,032 KB |
testcase_32 | AC | 155 ms
22,120 KB |
testcase_33 | AC | 169 ms
28,036 KB |
testcase_34 | AC | 72 ms
16,016 KB |
testcase_35 | AC | 112 ms
21,328 KB |
testcase_36 | AC | 140 ms
24,724 KB |
testcase_37 | AC | 125 ms
19,452 KB |
testcase_38 | AC | 242 ms
27,808 KB |
testcase_39 | AC | 224 ms
25,760 KB |
testcase_40 | AC | 212 ms
20,440 KB |
testcase_41 | AC | 36 ms
11,648 KB |
testcase_42 | AC | 169 ms
21,476 KB |
testcase_43 | AC | 37 ms
11,776 KB |
testcase_44 | AC | 35 ms
11,648 KB |
testcase_45 | AC | 41 ms
11,648 KB |
testcase_46 | AC | 35 ms
11,648 KB |
testcase_47 | AC | 35 ms
11,648 KB |
testcase_48 | AC | 34 ms
11,648 KB |
ソースコード
from bisect import bisect_left, bisect_right from math import inf from typing import NamedTuple class Frog(NamedTuple): coord: int amp: int def is_range(self, start: int, end: int) -> bool: return start <= self.coord <= end @property def range(self) -> tuple[int, int]: return self.coord-self.amp, self.coord+self.amp def main(): N, K = map(int, input().split()) X = list(map(int, input().split())) A = list(map(int, input().split())) frogs: list[Frog] = [Frog(coord, amp) for coord, amp in zip(X, A)] left_effect = X[K-1]-A[K-1] right_effect = X[K-1]+A[K-1] left_idx = K-1 right_idx = K idx_changed = True while idx_changed: new_gelo: list[Frog] = [] idx_changed = False left_idx_candidate = bisect_left(X, left_effect) right_idx_candidate = bisect_right(X, right_effect) if left_idx != left_idx_candidate: idx_changed = True new_gelo.extend(frogs[left_idx_candidate:left_idx]) left_idx = left_idx_candidate if right_idx != right_idx_candidate: idx_changed = True new_gelo.extend(frogs[right_idx:right_idx_candidate]) right_idx = right_idx_candidate for frog in new_gelo: left_range, right_range = frog.range left_effect = min(left_effect, left_range) right_effect = max(right_effect, right_range) print(right_idx - left_idx) if __name__ == "__main__": main()