結果
問題 | No.1231 Make a Multiple of Ten |
ユーザー | tzyvrn |
提出日時 | 2020-09-19 16:40:17 |
言語 | Rust (1.77.0 + proconio) |
結果 |
AC
|
実行時間 | 15 ms / 2,000 ms |
コード長 | 1,459 bytes |
コンパイル時間 | 12,109 ms |
コンパイル使用メモリ | 394,976 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-06-23 17:25:34 |
合計ジャッジ時間 | 13,389 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
6,812 KB |
testcase_01 | AC | 1 ms
6,816 KB |
testcase_02 | AC | 1 ms
6,940 KB |
testcase_03 | AC | 1 ms
6,944 KB |
testcase_04 | AC | 9 ms
6,940 KB |
testcase_05 | AC | 7 ms
6,940 KB |
testcase_06 | AC | 4 ms
6,940 KB |
testcase_07 | AC | 8 ms
6,944 KB |
testcase_08 | AC | 4 ms
6,944 KB |
testcase_09 | AC | 3 ms
6,940 KB |
testcase_10 | AC | 8 ms
6,944 KB |
testcase_11 | AC | 9 ms
6,940 KB |
testcase_12 | AC | 14 ms
6,940 KB |
testcase_13 | AC | 15 ms
6,940 KB |
testcase_14 | AC | 1 ms
6,944 KB |
testcase_15 | AC | 15 ms
6,940 KB |
コンパイルメッセージ
warning: unused import: `std::cmp::min` --> src/main.rs:1:5 | 1 | use std::cmp::min; | ^^^^^^^^^^^^^ | = note: `#[warn(unused_imports)]` on by default warning: use of deprecated method `core::str::<impl str>::trim_right`: superseded by `trim_end` --> src/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 method | 10 | let s = s.trim_end(); | ~~~~~~~~ warning: use of deprecated method `core::str::<impl str>::trim_right`: superseded by `trim_end` --> src/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 method | 22 | let s = s.trim_end(); | ~~~~~~~~
ソースコード
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; } let mut s = 0; for ai in a.iter().copied() { s += ai; s = s % 10; } let r = dfs(1, 0, 0, s, &cnt); println!("{}", n - r); } fn dfs(m: usize, c: usize, now: usize, t: usize, cnt: &Vec<usize>) -> usize { if m > 9 { return 100; } let mut ret = 100; for i in 0..=9 { if i > cnt[m] || c + i > 10 { break; } let now = (now + m * i) % 10; if now == t { ret = std::cmp::min(ret, c + i); } else { ret = std::cmp::min(ret, dfs(m + 1, c + i, now, t, cnt)); } } ret }