結果
問題 | No.1170 Never Want to Walk |
ユーザー | phspls |
提出日時 | 2022-12-30 23:38:53 |
言語 | Rust (1.77.0 + proconio) |
結果 |
AC
|
実行時間 | 270 ms / 2,000 ms |
コード長 | 3,119 bytes |
コンパイル時間 | 11,449 ms |
コンパイル使用メモリ | 376,088 KB |
実行使用メモリ | 14,720 KB |
最終ジャッジ日時 | 2024-11-25 22:00:50 |
合計ジャッジ時間 | 16,913 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
5,248 KB |
testcase_01 | AC | 1 ms
5,248 KB |
testcase_02 | AC | 1 ms
5,248 KB |
testcase_03 | AC | 1 ms
5,248 KB |
testcase_04 | AC | 1 ms
5,248 KB |
testcase_05 | AC | 0 ms
5,248 KB |
testcase_06 | AC | 1 ms
5,248 KB |
testcase_07 | AC | 0 ms
5,248 KB |
testcase_08 | AC | 1 ms
5,248 KB |
testcase_09 | AC | 0 ms
5,248 KB |
testcase_10 | AC | 1 ms
5,248 KB |
testcase_11 | AC | 1 ms
5,248 KB |
testcase_12 | AC | 2 ms
5,248 KB |
testcase_13 | AC | 3 ms
5,248 KB |
testcase_14 | AC | 2 ms
5,248 KB |
testcase_15 | AC | 2 ms
5,248 KB |
testcase_16 | AC | 2 ms
5,248 KB |
testcase_17 | AC | 2 ms
5,248 KB |
testcase_18 | AC | 2 ms
5,248 KB |
testcase_19 | AC | 2 ms
5,248 KB |
testcase_20 | AC | 2 ms
5,248 KB |
testcase_21 | AC | 2 ms
5,248 KB |
testcase_22 | AC | 2 ms
5,248 KB |
testcase_23 | AC | 2 ms
5,248 KB |
testcase_24 | AC | 2 ms
5,248 KB |
testcase_25 | AC | 2 ms
5,248 KB |
testcase_26 | AC | 2 ms
5,248 KB |
testcase_27 | AC | 266 ms
11,520 KB |
testcase_28 | AC | 251 ms
11,392 KB |
testcase_29 | AC | 270 ms
11,648 KB |
testcase_30 | AC | 260 ms
11,648 KB |
testcase_31 | AC | 270 ms
11,392 KB |
testcase_32 | AC | 251 ms
14,336 KB |
testcase_33 | AC | 260 ms
12,288 KB |
testcase_34 | AC | 250 ms
14,720 KB |
testcase_35 | AC | 257 ms
14,464 KB |
testcase_36 | AC | 241 ms
14,080 KB |
testcase_37 | AC | 243 ms
14,208 KB |
testcase_38 | AC | 255 ms
14,592 KB |
コンパイルメッセージ
warning: value assigned to `maxidx` is never read --> src/main.rs:94:13 | 94 | let mut maxidx = 0usize; | ^^^^^^ | = help: maybe it is overwritten before being read? = note: `#[warn(unused_assignments)]` on by default 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; let mut maxidx = 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); maxidx = ridx-1; maxval = maxval.max(x[maxidx]); 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)]); } }