結果

問題 No.979 Longest Divisor Sequence
ユーザー phsplsphspls
提出日時 2023-02-05 04:55:46
言語 Rust
(1.77.0)
結果
AC  
実行時間 563 ms / 2,000 ms
コード長 961 bytes
コンパイル時間 5,562 ms
コンパイル使用メモリ 161,572 KB
実行使用メモリ 12,680 KB
最終ジャッジ日時 2023-09-16 23:46:38
合計ジャッジ時間 7,675 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 0 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 6 ms
4,380 KB
testcase_11 AC 6 ms
4,380 KB
testcase_12 AC 6 ms
4,380 KB
testcase_13 AC 16 ms
4,992 KB
testcase_14 AC 563 ms
12,680 KB
testcase_15 AC 182 ms
6,736 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
warning: unused variable: `n`
 --> 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

warning: 1 warning emitted

ソースコード

diff #

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());
}
0