結果
問題 | No.1036 Make One With GCD 2 |
ユーザー | phspls |
提出日時 | 2023-01-23 03:21:04 |
言語 | Rust (1.77.0 + proconio) |
結果 |
TLE
|
実行時間 | - |
コード長 | 2,499 bytes |
コンパイル時間 | 15,850 ms |
コンパイル使用メモリ | 379,232 KB |
実行使用メモリ | 89,216 KB |
最終ジャッジ日時 | 2024-06-25 03:35:42 |
合計ジャッジ時間 | 34,781 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 328 ms
88,320 KB |
testcase_01 | AC | 271 ms
84,736 KB |
testcase_02 | AC | 394 ms
89,216 KB |
testcase_03 | AC | 55 ms
38,016 KB |
testcase_04 | AC | 110 ms
77,440 KB |
testcase_05 | AC | 1 ms
5,376 KB |
testcase_06 | AC | 1 ms
5,376 KB |
testcase_07 | AC | 149 ms
40,320 KB |
testcase_08 | AC | 122 ms
39,296 KB |
testcase_09 | AC | 394 ms
83,968 KB |
testcase_10 | AC | 346 ms
83,200 KB |
testcase_11 | AC | 366 ms
84,224 KB |
testcase_12 | AC | 344 ms
83,200 KB |
testcase_13 | AC | 598 ms
87,936 KB |
testcase_14 | AC | 567 ms
88,064 KB |
testcase_15 | AC | 476 ms
87,040 KB |
testcase_16 | AC | 476 ms
87,168 KB |
testcase_17 | AC | 493 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 | 470 ms
86,912 KB |
testcase_23 | AC | 365 ms
82,816 KB |
testcase_24 | AC | 482 ms
87,296 KB |
testcase_25 | AC | 444 ms
86,016 KB |
testcase_26 | AC | 449 ms
86,528 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 | 344 ms
88,704 KB |
testcase_39 | AC | 324 ms
88,576 KB |
testcase_40 | AC | 360 ms
82,816 KB |
testcase_41 | AC | 1,850 ms
88,704 KB |
testcase_42 | AC | 1,669 ms
88,704 KB |
testcase_43 | AC | 1,911 ms
88,704 KB |
testcase_44 | TLE | - |
コンパイルメッセージ
warning: method `find_closed` is never used --> src/main.rs:40:8 | 9 | / impl<T, F> SparseTable<T, F> where 10 | | T: std::fmt::Debug + Copy, 11 | | F: Fn(T, T) -> T, | |_________________- method in this implementation ... 40 | 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>>, 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); 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, 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 - (1usize << 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, 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);}