結果
問題 | No.1036 Make One With GCD 2 |
ユーザー | phspls |
提出日時 | 2023-01-23 03:27:19 |
言語 | Rust (1.77.0 + proconio) |
結果 |
TLE
(最新)
AC
(最初)
|
実行時間 | - |
コード長 | 2,648 bytes |
コンパイル時間 | 13,723 ms |
コンパイル使用メモリ | 378,932 KB |
実行使用メモリ | 89,088 KB |
最終ジャッジ日時 | 2024-06-25 03:40:39 |
合計ジャッジ時間 | 34,484 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 391 ms
88,320 KB |
testcase_01 | AC | 372 ms
84,608 KB |
testcase_02 | AC | 405 ms
89,088 KB |
testcase_03 | AC | 56 ms
38,016 KB |
testcase_04 | AC | 115 ms
77,440 KB |
testcase_05 | AC | 1 ms
5,376 KB |
testcase_06 | AC | 1 ms
5,376 KB |
testcase_07 | AC | 109 ms
40,320 KB |
testcase_08 | AC | 97 ms
39,296 KB |
testcase_09 | AC | 451 ms
83,968 KB |
testcase_10 | AC | 424 ms
83,200 KB |
testcase_11 | AC | 456 ms
84,224 KB |
testcase_12 | AC | 429 ms
83,328 KB |
testcase_13 | AC | 576 ms
87,936 KB |
testcase_14 | AC | 586 ms
87,936 KB |
testcase_15 | AC | 547 ms
86,912 KB |
testcase_16 | AC | 554 ms
87,168 KB |
testcase_17 | AC | 567 ms
87,680 KB |
testcase_18 | AC | 1 ms
5,376 KB |
testcase_19 | AC | 1 ms
5,376 KB |
testcase_20 | AC | 3 ms
5,376 KB |
testcase_21 | AC | 2 ms
5,376 KB |
testcase_22 | AC | 546 ms
87,040 KB |
testcase_23 | AC | 419 ms
82,816 KB |
testcase_24 | AC | 563 ms
87,424 KB |
testcase_25 | AC | 521 ms
86,016 KB |
testcase_26 | AC | 537 ms
86,608 KB |
testcase_27 | AC | 1 ms
5,376 KB |
testcase_28 | AC | 1 ms
5,376 KB |
testcase_29 | AC | 1 ms
5,376 KB |
testcase_30 | AC | 1 ms
5,376 KB |
testcase_31 | AC | 1 ms
5,376 KB |
testcase_32 | AC | 1 ms
5,376 KB |
testcase_33 | AC | 1 ms
5,376 KB |
testcase_34 | AC | 1 ms
5,376 KB |
testcase_35 | AC | 1 ms
5,376 KB |
testcase_36 | AC | 1 ms
5,376 KB |
testcase_37 | AC | 1 ms
5,376 KB |
testcase_38 | AC | 402 ms
88,832 KB |
testcase_39 | AC | 401 ms
88,704 KB |
testcase_40 | AC | 419 ms
82,816 KB |
testcase_41 | AC | 1,849 ms
88,576 KB |
testcase_42 | AC | 1,741 ms
88,576 KB |
testcase_43 | AC | 1,980 ms
88,576 KB |
testcase_44 | TLE | - |
コンパイルメッセージ
warning: method `find_closed` is never used --> src/main.rs:43:8 | 10 | / impl<T, F> SparseTable<T, F> where 11 | | T: std::fmt::Debug + Copy, 12 | | F: Fn(T, T) -> T, | |_________________- method in this implementation ... 43 | fn find_closed(&self, l: usize, r: usize) -> T { | ^^^^^^^^^^^ | = note: `#[warn(dead_code)]` on by default
ソースコード
#[derive(Debug, Clone)] struct SparseTable<T, F> { vals: Vec<Vec<T>>, block_size: Vec<usize>, operator: F, usize_bit_cnt: u32, } impl<T, F> SparseTable<T, F> where T: std::fmt::Debug + Copy, F: Fn(T, T) -> T, { fn new(v: &Vec<T>, unit: T, operator: F) -> Self { let size = usize::max_value().count_ones() - v.len().leading_zeros(); let size = size as usize; let limit = 1usize << size; let mut vals = Vec::with_capacity(size+1); let block_size = (0..=size).map(|i| 1usize << i).collect::<Vec<_>>(); vals.push(vec![unit; limit]); for i in 0..v.len() { vals[0][i] = v[i]; } for i in 1..=size { let length = 1usize << i; let jsize = limit+1-length; vals.push(vec![unit; jsize]); for start in 0..jsize { let left = start; let right = start + (1usize << (i-1)); vals[i][start] = operator(vals[i - 1][left], vals[i - 1][right]); } } Self { vals, block_size, operator, usize_bit_cnt: usize::max_value().count_ones() } } fn find_closed(&self, l: usize, r: usize) -> T { self.find(l, r+1) } fn find(&self, l: usize, r: usize) -> T { let length = r - l; if length == 1 { return self.vals[0][l]; } let idx = self.usize_bit_cnt - length.leading_zeros() - 1; let idx = idx as usize; let left = self.vals[idx][l]; let right = self.vals[idx][r - self.block_size[idx]]; (self.operator)(left, right) } } fn gcd(a: usize, b: usize) -> usize { if b == 0 { return a; } gcd(b, a%b) } fn main() { let mut n = String::new(); std::io::stdin().read_line(&mut n).ok(); let n: usize = n.trim().parse().unwrap(); let mut a = String::new(); std::io::stdin().read_line(&mut a).ok(); let a: Vec<usize> = a.trim().split_whitespace().map(|s| s.parse().unwrap()).collect(); let sparse_table = SparseTable::new(&a, 0usize, |x, y| gcd(x.max(y), x.min(y))); let mut result = 0usize; for i in 0..n { if a[i] == 1 { result += n - i; continue; } let mut lower = i+1; let mut upper = n; while upper > lower { let middle = (upper + lower + 1) / 2; if sparse_table.find(i, middle) > 1 { lower = middle; } else { upper = middle - 1; } } result += n - upper; } println!("{}", result);}