結果

問題 No.871 かえるのうた
ユーザー ThetaTheta
提出日時 2022-11-25 14:46:16
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 241 ms / 2,000 ms
コード長 1,532 bytes
コンパイル時間 1,100 ms
コンパイル使用メモリ 10,968 KB
実行使用メモリ 27,244 KB
最終ジャッジ日時 2023-08-20 09:46:28
合計ジャッジ時間 7,064 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 34 ms
9,920 KB
testcase_01 AC 34 ms
9,960 KB
testcase_02 AC 33 ms
9,972 KB
testcase_03 AC 33 ms
9,872 KB
testcase_04 AC 33 ms
9,988 KB
testcase_05 AC 33 ms
9,976 KB
testcase_06 AC 33 ms
9,888 KB
testcase_07 AC 33 ms
9,932 KB
testcase_08 AC 36 ms
10,408 KB
testcase_09 AC 37 ms
10,568 KB
testcase_10 AC 34 ms
10,052 KB
testcase_11 AC 34 ms
10,180 KB
testcase_12 AC 55 ms
13,356 KB
testcase_13 AC 38 ms
10,560 KB
testcase_14 AC 163 ms
27,244 KB
testcase_15 AC 163 ms
27,180 KB
testcase_16 AC 241 ms
26,348 KB
testcase_17 AC 155 ms
24,472 KB
testcase_18 AC 55 ms
13,312 KB
testcase_19 AC 167 ms
26,088 KB
testcase_20 AC 50 ms
11,604 KB
testcase_21 AC 88 ms
16,664 KB
testcase_22 AC 33 ms
9,980 KB
testcase_23 AC 32 ms
9,928 KB
testcase_24 AC 33 ms
9,932 KB
testcase_25 AC 36 ms
10,272 KB
testcase_26 AC 52 ms
11,308 KB
testcase_27 AC 50 ms
12,076 KB
testcase_28 AC 32 ms
10,020 KB
testcase_29 AC 97 ms
17,736 KB
testcase_30 AC 170 ms
21,880 KB
testcase_31 AC 36 ms
10,412 KB
testcase_32 AC 147 ms
20,348 KB
testcase_33 AC 161 ms
26,096 KB
testcase_34 AC 62 ms
14,736 KB
testcase_35 AC 102 ms
19,516 KB
testcase_36 AC 128 ms
22,816 KB
testcase_37 AC 110 ms
17,840 KB
testcase_38 AC 221 ms
26,068 KB
testcase_39 AC 205 ms
23,908 KB
testcase_40 AC 201 ms
18,244 KB
testcase_41 AC 32 ms
9,924 KB
testcase_42 AC 147 ms
19,400 KB
testcase_43 AC 33 ms
9,856 KB
testcase_44 AC 32 ms
9,932 KB
testcase_45 AC 37 ms
10,144 KB
testcase_46 AC 32 ms
9,976 KB
testcase_47 AC 33 ms
9,972 KB
testcase_48 AC 33 ms
9,924 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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()
0