結果

問題 No.372 It's automatic
ユーザー akakimidoriakakimidori
提出日時 2021-03-17 15:05:06
言語 Rust
(1.77.0)
結果
AC  
実行時間 985 ms / 6,000 ms
コード長 913 bytes
コンパイル時間 12,649 ms
コンパイル使用メモリ 401,904 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-27 03:44:35
合計ジャッジ時間 25,849 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,812 KB
testcase_01 AC 1 ms
6,940 KB
testcase_02 AC 1 ms
6,940 KB
testcase_03 AC 1 ms
6,940 KB
testcase_04 AC 966 ms
6,940 KB
testcase_05 AC 972 ms
6,940 KB
testcase_06 AC 971 ms
6,944 KB
testcase_07 AC 974 ms
6,944 KB
testcase_08 AC 977 ms
6,940 KB
testcase_09 AC 968 ms
6,944 KB
testcase_10 AC 972 ms
6,944 KB
testcase_11 AC 963 ms
6,940 KB
testcase_12 AC 980 ms
6,940 KB
testcase_13 AC 970 ms
6,940 KB
testcase_14 AC 976 ms
6,944 KB
testcase_15 AC 985 ms
6,944 KB
testcase_16 AC 1 ms
6,940 KB
testcase_17 AC 1 ms
6,940 KB
testcase_18 AC 1 ms
6,940 KB
testcase_19 AC 1 ms
6,940 KB
testcase_20 AC 1 ms
6,940 KB
testcase_21 AC 49 ms
6,940 KB
testcase_22 AC 50 ms
6,940 KB
testcase_23 AC 49 ms
6,940 KB
testcase_24 AC 49 ms
6,940 KB
testcase_25 AC 49 ms
6,940 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 mut ans = 0;
    let mut dp = vec![0; m];
    for k in s {
        let k = (k - b'0') as usize;
        let mut next = vec![0; m];
        for (i, dp) in dp.iter().enumerate() {
            next[(10 * i + k) % m] += *dp;
        }
        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;
        }
        dp = next;
        dp.iter_mut().for_each(|p| *p %= MOD);
    }
    ans %= MOD;
    println!("{}", ans);
}
0