結果
問題 | No.917 Make One With GCD |
ユーザー |
|
提出日時 | 2020-03-11 13:29:32 |
言語 | Rust (1.83.0 + proconio) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 960 bytes |
コンパイル時間 | 12,825 ms |
コンパイル使用メモリ | 389,520 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-06-24 11:14:34 |
合計ジャッジ時間 | 14,114 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 32 |
ソースコード
use std::io::*; fn gcd(a: u64, b: u64) -> u64 { if b == 0 { return a; } gcd(b, a % b) } fn main() { let mut s: String = String::new(); std::io::stdin().read_to_string(&mut s).ok(); let mut itr = s.trim().split_whitespace(); let n: usize = itr.next().unwrap().parse().unwrap(); let a: Vec<u64> = (0..n) .map(|_| itr.next().unwrap().parse().unwrap()) .collect(); let mut dp = std::collections::HashMap::new(); dp.insert(0u64, 1u64); for i in 0..n { let mut next = std::collections::HashMap::new(); for (&value, &count) in dp.iter() { // use let g = gcd(value, a[i]); let val = next.entry(g).or_insert(0); *val += count; // not use let val = next.entry(value).or_insert(0); *val += count; } dp = next; } let val = dp.entry(1).or_insert(0); println!("{}", *val); }