結果

問題 No.1231 Make a Multiple of Ten
ユーザー どららどらら
提出日時 2020-09-21 02:30:19
言語 Rust
(1.77.0)
結果
AC  
実行時間 39 ms / 2,000 ms
コード長 1,052 bytes
コンパイル時間 2,090 ms
コンパイル使用メモリ 149,624 KB
実行使用メモリ 12,496 KB
最終ジャッジ日時 2023-09-06 16:53:22
合計ジャッジ時間 3,110 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 19 ms
6,900 KB
testcase_05 AC 16 ms
6,332 KB
testcase_06 AC 6 ms
4,376 KB
testcase_07 AC 19 ms
6,976 KB
testcase_08 AC 10 ms
4,556 KB
testcase_09 AC 4 ms
4,376 KB
testcase_10 AC 17 ms
6,312 KB
testcase_11 AC 20 ms
7,336 KB
testcase_12 AC 37 ms
12,104 KB
testcase_13 AC 38 ms
12,496 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 39 ms
12,420 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

use std::cmp;
use std::io::*;
use std::str::FromStr;

fn calc(n: usize, v: Vec<i32>) -> i32 {
    let mut dp = vec![vec![-1; n + 1]; 10];
    dp[0][0] = 0;

    for i in 0..n {
        for j in 0..10 {
            if dp[j][i] < 0 {
                continue;
            }
            dp[j][i + 1] = cmp::max(dp[j][i + 1], dp[j][i]);
            let val = (v[i] % 10) as usize;
            dp[(j + val) % 10][i + 1] = cmp::max(dp[(j + val) % 10][i + 1], dp[j][i] + 1);
        }
    }

    /*
    for i in 0..10 {
        for j in 0..n + 1 {
            print!("{} ", dp[i][j]);
        }
        println!("");
    }
    */
    dp[0][n]
}

fn main() {
    let mut s = String::new();
    stdin().read_line(&mut s).ok();
    let mut it = s.split_whitespace().map(|x| i32::from_str(x).unwrap());
    let n = it.next().unwrap();

    let mut s = String::new();
    stdin().read_line(&mut s).ok();
    let v: Vec<i32> = s
        .split_whitespace()
        .map(|x| i32::from_str(x).unwrap())
        .collect();

    println!("{}", calc(n as usize, v));
}
0