結果
問題 |
No.1170 Never Want to Walk
|
ユーザー |
|
提出日時 | 2024-08-05 18:00:58 |
言語 | Rust (1.83.0 + proconio) |
結果 |
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 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 11 RE * 14 TLE * 1 -- * 11 |
ソースコード
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 }