結果
問題 | No.1170 Never Want to Walk |
ユーザー | phspls |
提出日時 | 2022-12-30 23:33:38 |
言語 | Rust (1.77.0 + proconio) |
結果 |
TLE
|
実行時間 | - |
コード長 | 3,025 bytes |
コンパイル時間 | 14,420 ms |
コンパイル使用メモリ | 378,660 KB |
実行使用メモリ | 19,840 KB |
最終ジャッジ日時 | 2024-05-04 11:24:41 |
合計ジャッジ時間 | 18,318 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
10,752 KB |
testcase_01 | AC | 1 ms
5,248 KB |
testcase_02 | AC | 0 ms
5,376 KB |
testcase_03 | AC | 1 ms
5,376 KB |
testcase_04 | AC | 1 ms
5,376 KB |
testcase_05 | AC | 1 ms
5,376 KB |
testcase_06 | AC | 1 ms
5,376 KB |
testcase_07 | AC | 1 ms
5,376 KB |
testcase_08 | AC | 0 ms
5,376 KB |
testcase_09 | AC | 0 ms
5,376 KB |
testcase_10 | AC | 1 ms
5,376 KB |
testcase_11 | AC | 1 ms
5,376 KB |
testcase_12 | AC | 2 ms
5,376 KB |
testcase_13 | AC | 2 ms
5,376 KB |
testcase_14 | AC | 2 ms
5,376 KB |
testcase_15 | AC | 3 ms
5,376 KB |
testcase_16 | AC | 3 ms
5,376 KB |
testcase_17 | AC | 3 ms
5,376 KB |
testcase_18 | AC | 2 ms
5,376 KB |
testcase_19 | AC | 2 ms
5,376 KB |
testcase_20 | AC | 2 ms
5,376 KB |
testcase_21 | AC | 2 ms
5,376 KB |
testcase_22 | AC | 7 ms
5,376 KB |
testcase_23 | AC | 3 ms
5,376 KB |
testcase_24 | AC | 6 ms
5,376 KB |
testcase_25 | AC | 6 ms
5,376 KB |
testcase_26 | AC | 4 ms
5,376 KB |
testcase_27 | AC | 272 ms
11,520 KB |
testcase_28 | AC | 265 ms
11,392 KB |
testcase_29 | AC | 270 ms
11,648 KB |
testcase_30 | AC | 287 ms
11,520 KB |
testcase_31 | AC | 292 ms
11,392 KB |
testcase_32 | TLE | - |
testcase_33 | -- | - |
testcase_34 | -- | - |
testcase_35 | -- | - |
testcase_36 | -- | - |
testcase_37 | -- | - |
testcase_38 | -- | - |
コンパイルメッセージ
warning: field `n` is never read --> src/main.rs:31:5 | 30 | struct UnionFind { | --------- field in this struct 31 | n: usize, | ^ | = note: `#[warn(dead_code)]` on by default warning: method `chain_cnt` is never used --> src/main.rs:74:8 | 37 | impl UnionFind { | -------------- method in this implementation ... 74 | fn chain_cnt(&mut self, i: usize) -> usize { | ^^^^^^^^^
ソースコード
fn lower_bound(target: usize, vals: &Vec<usize>) -> usize { let mut upper = vals.len(); let mut lower = 0usize; while upper > lower { let middle = (upper + lower) / 2; if vals[middle] < target { lower = middle+1; } else { upper = middle; } } upper } fn upper_bound(target: usize, vals: &Vec<usize>) -> usize { let mut upper = vals.len(); let mut lower = 0usize; while upper > lower { let middle = (upper + lower) / 2; if vals[middle] <= target { lower = middle+1; } else { upper = middle; } } upper } struct UnionFind { n: usize, parents: Vec<usize>, depths: Vec<usize>, chains: Vec<usize>, } impl UnionFind { fn new(n: usize) -> Self { UnionFind { n: n, parents: (0..n).collect(), depths: vec![0; n], chains: vec![1; n], } } fn equiv(&mut self, a: usize, b: usize) -> bool { self.find(a) == self.find(b) } fn unite(&mut self, a: usize, b: usize) { if self.equiv(a, b) { return; } let x = self.parents[a]; let y = self.parents[b]; if self.depths[x] > self.depths[y] { self.parents[x] = self.parents[y]; self.chains[y] += self.chains[x]; } else { self.parents[y] = self.parents[x]; self.chains[x] += self.chains[y]; if self.depths[x] == self.depths[y] { self.depths[x] += 1; } } } fn find(&mut self, a: usize) -> usize { if self.parents[a] == a { return a; } let p = self.find(self.parents[a]); self.parents[a] = p; p } fn chain_cnt(&mut self, i: usize) -> usize { let idx = self.find(i); self.chains[idx] } } fn main() { let mut nab = String::new(); std::io::stdin().read_line(&mut nab).ok(); let nab: Vec<usize> = nab.trim().split_whitespace().map(|s| s.parse().unwrap()).collect(); let n = nab[0]; let a = nab[1]; let b = nab[2]; let mut x = String::new(); std::io::stdin().read_line(&mut x).ok(); let x: Vec<usize> = x.trim().split_whitespace().map(|s| s.parse().unwrap()).collect(); let mut uf = UnionFind::new(n); let mut size = vec![1usize; n]; let mut maxval = 0usize; for i in 0..n { maxval = maxval.max(x[i]+a); let lidx = lower_bound(maxval, &x); let ridx = upper_bound(x[i]+b, &x); for j in lidx..ridx { let pi = uf.find(i); let pj = uf.find(j); if pi == pj { continue; } uf.unite(pi, pj); let p = uf.find(pi); if p == pi { size[pi] += size[pj]; size[pj] = 0; } else { size[pj] += size[pi]; size[pi] = 0; } } } for i in 0..n { println!("{}", size[uf.find(i)]); } }