結果

問題 No.1170 Never Want to Walk
ユーザー tabataba
提出日時 2024-08-05 18:00:58
言語 Rust
(1.77.0)
結果
RE  
実行時間 -
コード長 1,820 bytes
コンパイル時間 25,596 ms
コンパイル使用メモリ 399,436 KB
実行使用メモリ 53,140 KB
最終ジャッジ日時 2024-08-05 18:01:29
合計ジャッジ時間 23,279 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
13,884 KB
testcase_01 AC 1 ms
6,816 KB
testcase_02 AC 1 ms
6,940 KB
testcase_03 RE -
testcase_04 RE -
testcase_05 AC 1 ms
6,940 KB
testcase_06 RE -
testcase_07 AC 1 ms
6,944 KB
testcase_08 AC 1 ms
6,940 KB
testcase_09 AC 1 ms
6,940 KB
testcase_10 AC 1 ms
6,940 KB
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 AC 119 ms
19,840 KB
testcase_23 AC 41 ms
6,944 KB
testcase_24 AC 122 ms
19,840 KB
testcase_25 AC 134 ms
19,840 KB
testcase_26 AC 66 ms
10,112 KB
testcase_27 TLE -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

fn main() {
    proconio::input! {
        n: usize,
        a: i64,
        b: i64,
        x: [i64; n],
    }
    let mut stations: HashMap<usize, HashSet<usize>> =
        (0..n).into_iter().map(|i| (i, HashSet::new())).collect();
    for i in 0..n {
        for j in (0..i).rev().skip(1) {
            let abs = (x[j] - x[i]).abs();
            if between(a, b, abs) {
                stations.get_mut(&i).unwrap().insert(j);
            } else if abs > b {
                break;
            }
        }
        for j in (i..n).skip(1) {
            let abs = (x[j] - x[i]).abs();
            if between(a, b, abs) {
                stations.get_mut(&i).unwrap().insert(j);
            } else if abs > b {
                break;
            }
        }
    }

    let mut groups = vec![];
    loop {
        let mut visited = HashSet::new();
        if let Some(s) = stations.iter().find(|x| !x.1.is_empty()) {
            visited.insert(*s.0);
        } else {
            break;
        }
        loop {
            let mut inserted = false;
            for s in visited.clone() {
                for v in stations.get(&s).unwrap().iter() {
                    inserted |= visited.insert(*v);
                }
            }
            if !inserted {
                break;
            }
        }
        for v in visited.iter() {
            stations.remove(v);
        }
        groups.push(visited);
    }
    for s in stations {
        groups.push(HashSet::from_iter([s.0]));
    }
    let stations = (0..n)
        .into_iter()
        .map(|i| groups.iter().find(|x| x.contains(&i)).unwrap().len())
        .collect::<Vec<usize>>();
    for s in stations {
        println!("{}", s);
    }
}

fn between(a: i64, b: i64, x: i64) -> bool {
    a <= x && x <= b
}
0