結果

問題 No.137 貯金箱の焦り
ユーザー akakimidoriakakimidori
提出日時 2021-01-28 15:59:42
言語 Rust
(1.77.0)
結果
AC  
実行時間 58 ms / 5,000 ms
コード長 1,117 bytes
コンパイル時間 2,554 ms
コンパイル使用メモリ 153,844 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-08 06:49:45
合計ジャッジ時間 4,325 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 58 ms
4,376 KB
testcase_13 AC 4 ms
4,376 KB
testcase_14 AC 28 ms
4,376 KB
testcase_15 AC 25 ms
4,376 KB
testcase_16 AC 23 ms
4,380 KB
testcase_17 AC 9 ms
4,376 KB
testcase_18 AC 23 ms
4,376 KB
testcase_19 AC 25 ms
4,376 KB
testcase_20 AC 1 ms
4,380 KB
testcase_21 AC 13 ms
4,380 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 3 ms
4,380 KB
testcase_24 AC 7 ms
4,376 KB
testcase_25 AC 16 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

fn read() -> (usize, Vec<usize>) {
    use std::io::*;
    let mut s = String::new();
    std::io::stdin().read_to_string(&mut s).unwrap();
    let mut it = s.trim().split_whitespace();
    let mut next = || it.next().unwrap();
    let n: usize = next().parse().unwrap();
    let m: usize = next().parse().unwrap();
    (m, (0..n).flat_map(|_| next().parse()).collect())
}

fn main() {
    let (mut m, a) = read();
    const MOD: u32 = 1_234_567_891;
    let mut dp = vec![1];
    let mut next = vec![];
    while m > 0 {
        for &a in a.iter() {
            next.clear();
            next.resize(dp.len() + a, 0);
            next[..dp.len()].clone_from_slice(&dp);
            for (next, dp) in next[a..].iter_mut().zip(dp.iter()) {
                let v = *next + *dp;
                *next = if v >= MOD { v - MOD } else { v };
            }
            std::mem::swap(&mut dp, &mut next);
        }
        next.clear();
        for dp in dp.iter().skip(m & 1).step_by(2) {
            next.push(*dp);
        }
        std::mem::swap(&mut dp, &mut next);
        m >>= 1;
    }
    println!("{}", dp[0]);
}
0