結果
| 問題 |
No.979 Longest Divisor Sequence
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2023-02-05 04:55:46 |
| 言語 | Rust (1.83.0 + proconio) |
| 結果 |
AC
|
| 実行時間 | 560 ms / 2,000 ms |
| コード長 | 961 bytes |
| コンパイル時間 | 12,969 ms |
| コンパイル使用メモリ | 378,328 KB |
| 実行使用メモリ | 12,868 KB |
| 最終ジャッジ日時 | 2024-07-03 22:19:33 |
| 合計ジャッジ時間 | 15,077 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 16 |
コンパイルメッセージ
warning: unused variable: `n` --> src/main.rs:7:9 | 7 | let n: usize = n.trim().parse().unwrap(); | ^ help: if this is intentional, prefix it with an underscore: `_n` | = note: `#[warn(unused_variables)]` on by default
ソースコード
use std::collections::HashMap;
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 mut result = HashMap::new();
for &v in a.iter() {
let mut val = 1usize;
if v > 1 {
for i in 1..=(v as f64).sqrt() as usize {
if v % i == 0 {
val = val.max(1 + *result.get(&i).unwrap_or(&0usize));
if i > 1 {
val = val.max(1 + *result.get(&(v/i)).unwrap_or(&0usize));
}
}
}
}
if !result.contains_key(&v) || val > *result.get(&v).unwrap() {
result.insert(v, val);
}
}
println!("{}", result.values().max().unwrap());
}