結果
問題 | No.871 かえるのうた |
ユーザー |
|
提出日時 | 2022-11-25 14:46:16 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
AC
|
実行時間 | 252 ms / 2,000 ms |
コード長 | 1,532 bytes |
コンパイル時間 | 91 ms |
コンパイル使用メモリ | 12,672 KB |
実行使用メモリ | 30,052 KB |
最終ジャッジ日時 | 2024-11-30 11:11:21 |
合計ジャッジ時間 | 5,655 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 49 |
ソースコード
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()