結果

問題 No.372 It's automatic
ユーザー akakimidoriakakimidori
提出日時 2021-03-17 15:08:51
言語 Rust
(1.77.0)
結果
AC  
実行時間 641 ms / 6,000 ms
コード長 1,094 bytes
コンパイル時間 12,604 ms
コンパイル使用メモリ 402,656 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-27 03:44:55
合計ジャッジ時間 21,044 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 0 ms
6,812 KB
testcase_01 AC 1 ms
6,940 KB
testcase_02 AC 0 ms
6,940 KB
testcase_03 AC 1 ms
6,940 KB
testcase_04 AC 630 ms
6,944 KB
testcase_05 AC 634 ms
6,944 KB
testcase_06 AC 635 ms
6,944 KB
testcase_07 AC 639 ms
6,944 KB
testcase_08 AC 641 ms
6,944 KB
testcase_09 AC 638 ms
6,940 KB
testcase_10 AC 637 ms
6,944 KB
testcase_11 AC 627 ms
6,940 KB
testcase_12 AC 641 ms
6,940 KB
testcase_13 AC 634 ms
6,940 KB
testcase_14 AC 638 ms
6,944 KB
testcase_15 AC 641 ms
6,944 KB
testcase_16 AC 1 ms
6,940 KB
testcase_17 AC 1 ms
6,944 KB
testcase_18 AC 1 ms
6,940 KB
testcase_19 AC 1 ms
6,944 KB
testcase_20 AC 1 ms
6,940 KB
testcase_21 AC 31 ms
6,944 KB
testcase_22 AC 31 ms
6,944 KB
testcase_23 AC 31 ms
6,944 KB
testcase_24 AC 31 ms
6,940 KB
testcase_25 AC 30 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

fn main() {
    let (s, m) = read();
    const MOD: u64 = 1_000_000_007;
    let add = 10 % m;
    let mut ans = 0;
    let mut dp = vec![0; m];
    let mut next = vec![0; m];
    for k in s {
        let k = (k - b'0') as usize;
        next.clear();
        next.resize(m, 0);
        let mut pos = k % m;
        for dp in dp.iter() {
            next[pos] += *dp;
            pos += add;
            if pos >= m {
                pos -= m;
            }
        }
        if k > 0 {
            next[k % m] += 1;
        }
        ans += next[0] + (k == 0) as u64;
        for (next, dp) in next.iter_mut().zip(dp.iter()) {
            *next += *dp;
        }
        std::mem::swap(&mut dp, &mut next);
        dp.iter_mut().for_each(|p| *p %= MOD);
    }
    ans %= MOD;
    println!("{}", ans);
}
0