結果

問題 No.1085 桁和の桁和
ユーザー tonyu0tonyu0
提出日時 2020-06-20 01:15:49
言語 Rust
(1.77.0)
結果
WA  
実行時間 -
コード長 1,228 bytes
コンパイル時間 749 ms
コンパイル使用メモリ 146,964 KB
実行使用メモリ 14,220 KB
最終ジャッジ日時 2023-09-30 06:29:22
合計ジャッジ時間 3,122 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 WA -
testcase_10 AC 1 ms
4,376 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 6 ms
4,380 KB
testcase_14 AC 18 ms
6,372 KB
testcase_15 AC 40 ms
12,360 KB
testcase_16 AC 39 ms
12,124 KB
testcase_17 AC 20 ms
6,632 KB
testcase_18 AC 11 ms
4,380 KB
testcase_19 AC 36 ms
11,104 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 23 ms
7,692 KB
testcase_22 AC 33 ms
10,496 KB
testcase_23 AC 4 ms
4,380 KB
testcase_24 AC 1 ms
4,376 KB
testcase_25 AC 21 ms
7,176 KB
testcase_26 AC 41 ms
12,720 KB
testcase_27 AC 34 ms
10,496 KB
testcase_28 AC 47 ms
14,056 KB
testcase_29 AC 26 ms
8,140 KB
testcase_30 AC 23 ms
7,684 KB
testcase_31 AC 40 ms
12,100 KB
testcase_32 AC 29 ms
8,960 KB
testcase_33 AC 64 ms
14,072 KB
testcase_34 AC 65 ms
14,064 KB
testcase_35 AC 65 ms
14,072 KB
testcase_36 AC 65 ms
14,076 KB
testcase_37 AC 65 ms
14,088 KB
testcase_38 AC 65 ms
14,220 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

use std::io::*;
const MOD: usize = 1_000_000_007;

fn main() {
    let mut s: String = String::new();
    std::io::stdin().read_to_string(&mut s).ok();
    let mut itr = s.trim().split_whitespace();
    let s: Vec<char> = itr.next().unwrap().chars().collect();
    let n = s.len();
    let d: usize = itr.next().unwrap().parse().unwrap();

    // ketawa zero is zenbu zero
    if d == 0 {
        let mut zero = true;
        for i in 0..n {
            if s[i] != '?' && s[i] != '0' {
                zero = false;
                break;
            }
        }
        println!("{}", zero as u32);
        return;
    }

    let mut dp = vec![vec![0; 10]; n + 1];
    dp[0][0] = 1;
    for i in 0..n {
        for j in 0..10 {
            // 桁和がjの場合から遷移
            if s[i] == '?' {
                for k in 0..10 {
                    dp[i + 1][(j * 10 + k) % 9] += dp[i][j];
                    dp[i + 1][(j * 10 + k) % 9] %= MOD;
                }
            } else {
                let x = (s[i] as u8 - '0' as u8) as usize;
                dp[i + 1][(j * 10 + x) % 9] += dp[i][j];
                dp[i + 1][(j * 10 + x) % 9] %= MOD;
            }
        }
    }
    println!("{}", dp[n][d % 9]);
}
0