結果

問題 No.871 かえるのうた
ユーザー Masaki Kitaguchi
提出日時 2022-02-08 01:21:47
言語 Rust
(1.83.0 + proconio)
結果
WA  
実行時間 -
コード長 2,327 bytes
コンパイル時間 11,884 ms
コンパイル使用メモリ 394,328 KB
実行使用メモリ 14,876 KB
最終ジャッジ日時 2024-06-22 18:22:03
合計ジャッジ時間 16,869 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 13 WA * 3 TLE * 1 -- * 32
権限があれば一括ダウンロードができます

ソースコード

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 = {
                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,
                    }
                }
                match i {
                    i if i == 0 => 0,
                    _ => right,
                }
            };
            let ub = {
                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,
                    }
                }
                match i {
                    i if i == (n - 1) => n - 1,
                    _ => left,
                }
            };

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

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