結果

問題 No.1085 桁和の桁和
ユーザー phsplsphspls
提出日時 2023-01-12 00:27:12
言語 Rust
(1.77.0)
結果
AC  
実行時間 51 ms / 2,000 ms
コード長 1,185 bytes
コンパイル時間 745 ms
コンパイル使用メモリ 146,356 KB
実行使用メモリ 12,452 KB
最終ジャッジ日時 2023-08-24 04:44:45
合計ジャッジ時間 2,852 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 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,380 KB
testcase_07 AC 1 ms
4,380 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 1 ms
4,376 KB
testcase_13 AC 5 ms
4,380 KB
testcase_14 AC 11 ms
4,380 KB
testcase_15 AC 23 ms
6,528 KB
testcase_16 AC 23 ms
6,588 KB
testcase_17 AC 12 ms
4,376 KB
testcase_18 AC 6 ms
4,380 KB
testcase_19 AC 21 ms
5,928 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 14 ms
4,512 KB
testcase_22 AC 19 ms
5,712 KB
testcase_23 AC 3 ms
4,376 KB
testcase_24 AC 2 ms
4,380 KB
testcase_25 AC 12 ms
4,376 KB
testcase_26 AC 24 ms
6,840 KB
testcase_27 AC 19 ms
5,724 KB
testcase_28 AC 27 ms
7,340 KB
testcase_29 AC 15 ms
4,768 KB
testcase_30 AC 14 ms
4,504 KB
testcase_31 AC 23 ms
6,568 KB
testcase_32 AC 16 ms
5,024 KB
testcase_33 AC 51 ms
12,344 KB
testcase_34 AC 51 ms
12,452 KB
testcase_35 AC 51 ms
12,340 KB
testcase_36 AC 51 ms
12,404 KB
testcase_37 AC 51 ms
12,408 KB
testcase_38 AC 51 ms
12,448 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

const MOD: usize = 1e9 as usize + 7;

fn main() {
    let mut t = String::new();
    std::io::stdin().read_line(&mut t).ok();
    let t = t.trim().chars().collect::<Vec<_>>();
    let mut d = String::new();
    std::io::stdin().read_line(&mut d).ok();
    let d: usize = d.trim().parse().unwrap();

    let contains_zero_only_pattern = !t.iter().any(|&c| c != '0' && c != '?');
    if d == 0 {
        if contains_zero_only_pattern {
            println!("1");
        } else {
            println!("0");
        }
        return;
    }
    let summary = t.iter().filter(|&&c| c != '?').map(|&c| c as usize - '0' as usize).sum::<usize>() % 9;
    let cnt = t.iter().filter(|&&c| c == '?').count();
    let mut dp = vec![vec![0usize; 9]; cnt+1];
    dp[0][summary] = 1;
    for i in 0..cnt {
        for j in 0..9 {
            if dp[i][j] == 0 { continue; }
            for k in 0..10 {
                let jidx = (j+k)%9;
                dp[i+1][jidx] += dp[i][j];
                dp[i+1][jidx] %= MOD;
            }
        }
    }
    let d = d % 9;
    let result = (MOD + dp[cnt][d] - if d == 0 && contains_zero_only_pattern { 1 } else { 0 }) % MOD;
    println!("{}", result);
}
0