結果

問題 No.1085 桁和の桁和
ユーザー tonyu0tonyu0
提出日時 2020-06-20 01:02:41
言語 Rust
(1.77.0)
結果
WA  
実行時間 -
コード長 1,030 bytes
コンパイル時間 777 ms
コンパイル使用メモリ 146,396 KB
実行使用メモリ 14,080 KB
最終ジャッジ日時 2023-09-30 06:29:05
合計ジャッジ時間 2,808 ms
ジャッジサーバーID
(参考情報)
judge15 / 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 WA -
testcase_04 WA -
testcase_05 WA -
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 AC 1 ms
4,376 KB
testcase_10 WA -
testcase_11 AC 1 ms
4,376 KB
testcase_12 WA -
testcase_13 AC 6 ms
4,380 KB
testcase_14 AC 17 ms
6,360 KB
testcase_15 AC 38 ms
12,432 KB
testcase_16 AC 36 ms
12,152 KB
testcase_17 AC 17 ms
6,620 KB
testcase_18 AC 10 ms
4,376 KB
testcase_19 AC 32 ms
11,092 KB
testcase_20 WA -
testcase_21 AC 20 ms
7,696 KB
testcase_22 AC 28 ms
10,540 KB
testcase_23 AC 3 ms
4,380 KB
testcase_24 AC 1 ms
4,380 KB
testcase_25 AC 18 ms
7,164 KB
testcase_26 WA -
testcase_27 AC 30 ms
10,460 KB
testcase_28 AC 42 ms
14,080 KB
testcase_29 AC 23 ms
8,224 KB
testcase_30 AC 20 ms
7,684 KB
testcase_31 AC 35 ms
12,128 KB
testcase_32 AC 24 ms
8,964 KB
testcase_33 AC 58 ms
14,080 KB
testcase_34 AC 58 ms
14,064 KB
testcase_35 AC 58 ms
14,080 KB
testcase_36 AC 59 ms
14,016 KB
testcase_37 AC 60 ms
14,068 KB
testcase_38 AC 58 ms
14,076 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();

    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;
            }
        }
    }
    if d % 9 == 0 {
        println!("{}", dp[n][d % 9] / 2);
    } else {
        println!("{}", dp[n][d % 9]);
    }
}
0