結果

問題 No.1170 Never Want to Walk
ユーザー taba
提出日時 2024-08-06 10:20:14
言語 Rust
(1.83.0 + proconio)
結果
AC  
実行時間 295 ms / 2,000 ms
コード長 1,788 bytes
コンパイル時間 15,421 ms
コンパイル使用メモリ 381,760 KB
実行使用メモリ 14,624 KB
最終ジャッジ日時 2024-08-06 10:20:36
合計ジャッジ時間 19,275 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 37
権限があれば一括ダウンロードができます
コンパイルメッセージ
warning: unused imports: `BTreeSet`, `HashMap`, `HashSet`
 --> src/main.rs:1:24
  |
1 | use std::collections::{BTreeSet, HashMap, HashSet};
  |                        ^^^^^^^^  ^^^^^^^  ^^^^^^^
  |
  = note: `#[warn(unused_imports)]` on by default

ソースコード

diff #

use std::collections::{BTreeSet, HashMap, HashSet};

fn main() {
    proconio::input! {
        n: usize,
        a: i64,
        b: i64,
        x: [i64; n],
    }
    let mut x = x.into_iter().enumerate().collect::<Vec<_>>();
    let mut groups = vec![];
    loop {
        let Some(station) = x.pop() else {
            break;
        };
        let mut stations = vec![station];
        let mut group = vec![station];

        while !stations.is_empty() {
            let Some(station) = stations.pop() else {
                break;
            };
            let first = x.partition_point(|x| x.1 < station.1 + a);
            let last = x.partition_point(|x| x.1 <= station.1 + b);
            // eprintln!(
            //     "plus {station:?}: {} {}, {:?}, {}",
            //     first,
            //     last,
            //     &x[first..last],
            //     stations.len()
            // );
            group.extend(x.drain(first..last).inspect(|x| {
                stations.push(*x);
            }));

            let first = x.partition_point(|x| x.1 < station.1 - b);
            let last = x.partition_point(|x| x.1 <= station.1 - a);
            // eprintln!(
            //     "minus {station:?}: {} {} {:?}, {}",
            //     first,
            //     last,
            //     &x[first..last],
            //     stations.len()
            // );
            group.extend(x.drain(first..last).inspect(|x| {
                stations.push(*x);
            }));
        }
        groups.push(group);
    }
    //eprintln!("{:?}", groups);
    let mut v = vec![u64::MAX; n];
    for group in groups {
        for station in group.iter() {
            v[station.0] = group.len() as u64;
        }
    }
    for i in 0..n {
        println!("{}", v[i]);
    }
}
0