結果

問題 No.390 最長の数列
ユーザー phsplsphspls
提出日時 2020-07-25 15:40:53
言語 Rust
(1.77.0)
結果
AC  
実行時間 53 ms / 5,000 ms
コード長 630 bytes
コンパイル時間 2,053 ms
コンパイル使用メモリ 145,248 KB
実行使用メモリ 11,320 KB
最終ジャッジ日時 2023-09-09 14:00:27
合計ジャッジ時間 3,978 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 16 ms
6,240 KB
testcase_06 AC 53 ms
11,308 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 3 ms
4,376 KB
testcase_09 AC 12 ms
9,808 KB
testcase_10 AC 29 ms
11,320 KB
testcase_11 AC 28 ms
11,260 KB
testcase_12 AC 27 ms
11,300 KB
testcase_13 AC 24 ms
11,008 KB
testcase_14 AC 16 ms
4,376 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 4 ms
4,376 KB
testcase_17 AC 12 ms
9,852 KB
testcase_18 AC 11 ms
9,972 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

use std::cmp::max;

//TODO
fn main() {
    let mut n = String::new();
    std::io::stdin().read_line(&mut n).ok();
    let n: usize = n.trim().parse().unwrap();
    let mut x = String::new();
    std::io::stdin().read_line(&mut x).ok();
    let mut x: Vec<usize> = x.trim().split_whitespace().map(|s| s.parse().unwrap()).collect();
    x.sort();

    let maxval = x[n-1];
    let mut dp: Vec<usize> = vec![0; maxval + 1];
    for &v in x.iter() {
        dp[v] += 1;
        for i in 2..=maxval/v {
            dp[v*i] = max(dp[v], dp[v*i]);
        }
    }
    let result = dp.iter().max().unwrap();
    println!("{}", result);
}
0