結果

問題 No.1231 Make a Multiple of Ten
ユーザー phsplsphspls
提出日時 2022-11-11 10:51:09
言語 Rust
(1.77.0)
結果
AC  
実行時間 39 ms / 2,000 ms
コード長 642 bytes
コンパイル時間 4,102 ms
コンパイル使用メモリ 145,696 KB
実行使用メモリ 19,468 KB
最終ジャッジ日時 2023-10-11 07:07:20
合計ジャッジ時間 3,419 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 1 ms
4,352 KB
testcase_03 AC 1 ms
4,352 KB
testcase_04 AC 19 ms
9,856 KB
testcase_05 AC 17 ms
8,960 KB
testcase_06 AC 8 ms
4,760 KB
testcase_07 AC 20 ms
10,180 KB
testcase_08 AC 11 ms
6,272 KB
testcase_09 AC 6 ms
4,348 KB
testcase_10 AC 17 ms
9,288 KB
testcase_11 AC 21 ms
10,752 KB
testcase_12 AC 37 ms
18,348 KB
testcase_13 AC 39 ms
19,284 KB
testcase_14 AC 1 ms
4,352 KB
testcase_15 AC 39 ms
19,468 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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 dp = vec![vec![-1; 10]; n+1];
    dp[0][0] = 0;
    for i in 0..n {
        for j in 0..10 {
            if dp[i][j] < 0 { continue; }
            dp[i+1][j] = dp[i+1][j].max(dp[i][j]);
            let idx = (j+a[i]) % 10;
            dp[i+1][idx] = dp[i+1][idx].max(dp[i][j]+1);
        }
    }
    println!("{}", dp[n][0]);
}
0