結果
| 問題 |
No.917 Make One With GCD
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-03-11 13:28:14 |
| 言語 | Rust (1.83.0 + proconio) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 954 bytes |
| コンパイル時間 | 16,174 ms |
| コンパイル使用メモリ | 379,744 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-11-16 00:07:21 |
| 合計ジャッジ時間 | 15,074 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 18 WA * 14 |
ソースコード
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(0, 1);
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);
}