結果

問題 No.1231 Make a Multiple of Ten
ユーザー tzyvrntzyvrn
提出日時 2020-09-19 00:09:31
言語 Rust
(1.77.0)
結果
AC  
実行時間 14 ms / 2,000 ms
コード長 1,361 bytes
コンパイル時間 1,121 ms
コンパイル使用メモリ 154,560 KB
実行使用メモリ 5,616 KB
最終ジャッジ日時 2023-09-05 18:24:40
合計ジャッジ時間 2,111 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 7 ms
4,376 KB
testcase_05 AC 7 ms
4,380 KB
testcase_06 AC 3 ms
4,380 KB
testcase_07 AC 8 ms
4,376 KB
testcase_08 AC 4 ms
4,380 KB
testcase_09 AC 3 ms
4,380 KB
testcase_10 AC 7 ms
4,376 KB
testcase_11 AC 8 ms
4,376 KB
testcase_12 AC 14 ms
5,196 KB
testcase_13 AC 14 ms
5,616 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 14 ms
5,584 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
warning: use of deprecated associated function `core::str::<impl str>::trim_right`: superseded by `trim_end`
  --> Main.rs:10:23
   |
10 |             let s = s.trim_right();
   |                       ^^^^^^^^^^
...
31 |     let n = getl!(usize);
   |             ------------ in this macro invocation
   |
   = note: `#[warn(deprecated)]` on by default
   = note: this warning originates in the macro `getl` (in Nightly builds, run with -Z macro-backtrace for more info)
help: replace the use of the deprecated associated function
   |
10 |             let s = s.trim_end();
   |                       ~~~~~~~~

warning: use of deprecated associated function `core::str::<impl str>::trim_right`: superseded by `trim_end`
  --> Main.rs:22:19
   |
22 |         let s = s.trim_right();
   |                   ^^^^^^^^^^
...
32 |     let a = getl_vec!(usize);
   |             ---------------- in this macro invocation
   |
   = note: this warning originates in the macro `getl_vec` (in Nightly builds, run with -Z macro-backtrace for more info)
help: replace the use of the deprecated associated function
   |
22 |         let s = s.trim_end();
   |                   ~~~~~~~~

warning: 2 warnings emitted

ソースコード

diff #

use std::cmp::min;

//{{{
#[allow(unused_macros)]
macro_rules! getl {
    ( $( $t:ty ),* ) => {
        {
            let mut s = String::new();
            std::io::stdin().read_line(&mut s).unwrap();
            let s = s.trim_right();
            let mut ws = s.split_whitespace();
            ($(ws.next().unwrap().parse::<$t>().unwrap()),*)
        }
    };
}

#[allow(unused_macros)]
macro_rules! getl_vec {
    ( $t:ty ) => {{
        let mut s = String::new();
        std::io::stdin().read_line(&mut s).unwrap();
        let s = s.trim_right();
        s.split_whitespace()
            .map(|x| x.parse().unwrap())
            .collect::<Vec<$t>>()
    }};
}
//}}}

fn main() {
    let n = getl!(usize);
    let a = getl_vec!(usize);

    let mut cnt = vec![0usize; 10];
    for ai in a.iter().copied() {
        cnt[ai % 10] += 1;
    }
    dbg!(&cnt);

    let mut dp = vec![100usize; 10];
    dp[0] = 0;
    for m in 0..10 {
        let mut next = vec![100usize; 10];
        for i in 0..10 {
            for j in 0..=min(9, cnt[m]) {
                next[(i + m * j) % 10] = min(next[(i + m * j) % 10], dp[i] + j);
            }
        }
        dp = next;
        dbg!(&dp);
    }
    dbg!(&dp);

    let mut s = 0;
    for ai in a.iter().copied() {
        s += ai;
        s = s % 10;
    }

    let ans = n - dp[s];
    println!("{}", ans);
}
0