結果

問題 No.871 かえるのうた
ユーザー Masaki KitaguchiMasaki Kitaguchi
提出日時 2022-02-08 01:31:33
言語 Rust
(1.77.0)
結果
TLE  
実行時間 -
コード長 2,333 bytes
コンパイル時間 1,590 ms
コンパイル使用メモリ 155,344 KB
実行使用メモリ 13,040 KB
最終ジャッジ日時 2023-09-04 21:05:05
合計ジャッジ時間 6,195 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,384 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,384 KB
testcase_05 AC 1 ms
4,384 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,384 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,384 KB
testcase_11 AC 1 ms
4,384 KB
testcase_12 AC 3 ms
4,380 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 19 ms
7,560 KB
testcase_15 AC 19 ms
7,572 KB
testcase_16 TLE -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
testcase_45 -- -
testcase_46 -- -
testcase_47 -- -
testcase_48 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#[macro_export]
macro_rules! setup {
    { mut $input:ident: SplitWhitespace $(,)? } => {
        use std::io::Read;
        let mut buf = String::new();
        std::io::stdin().read_to_string(&mut buf).ok();
        let mut $input = buf.split_whitespace();
    };
}

#[macro_export]
macro_rules! parse_next {
    ($str_iter:expr) => {
        $str_iter.next().unwrap().parse().ok().unwrap()
    };
}

#[allow(unused_imports)]
use std::collections::{HashMap, HashSet, VecDeque};

fn main() {
    setup! { mut input: SplitWhitespace };

    let n: usize = parse_next!(input);
    let k: usize = parse_next!(input);
    let x: Vec<i64> = (0..n).map(|_| parse_next!(input)).collect();
    let a: Vec<i64> = (0..n).map(|_| parse_next!(input)).collect();

    let ans = (|| {
        let mut queue = VecDeque::new();
        let mut visited = HashSet::new();
        {
            let root = k - 1;
            queue.push_back(root);
            visited.insert(root);
        }
        while !queue.is_empty() {
            let i = queue.pop_front().unwrap();

            let lb = (|| {
                if x[i] - a[i] <= x[0] {
                    return 0;
                }
                let mut left = 0;
                let mut right = n;
                while right - left > 1 {
                    let mid = (left + right) / 2;
                    match x[i] - a[i] <= x[mid] {
                        true => right = mid,
                        false => left = mid,
                    }
                }
                right
            })();
            let ub = (|| {
                if x[n - 1] <= x[i] + a[i] {
                    return n - 1;
                }
                let mut left = 0;
                let mut right = n;
                while right - left > 1 {
                    let mid = (left + right) / 2;
                    match x[mid] <= x[i] + a[i] {
                        true => left = mid,
                        false => right = mid,
                    }
                }
                left
            })();

            for j in lb..=ub {
                if visited.contains(&j) {
                    continue;
                }
                queue.push_back(j);
                visited.insert(j);
            }
        }
        visited.len()
    })();

    println!("{}", ans);
}
0