結果

問題 No.1085 桁和の桁和
ユーザー phsplsphspls
提出日時 2023-01-04 23:16:11
言語 Rust
(1.77.0)
結果
AC  
実行時間 72 ms / 2,000 ms
コード長 1,443 bytes
コンパイル時間 2,375 ms
コンパイル使用メモリ 146,016 KB
実行使用メモリ 14,016 KB
最終ジャッジ日時 2023-08-18 19:47:18
合計ジャッジ時間 6,448 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,380 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,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 5 ms
4,376 KB
testcase_14 AC 15 ms
4,380 KB
testcase_15 AC 32 ms
7,368 KB
testcase_16 AC 31 ms
7,116 KB
testcase_17 AC 16 ms
4,496 KB
testcase_18 AC 9 ms
4,376 KB
testcase_19 AC 28 ms
6,816 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 19 ms
4,828 KB
testcase_22 AC 26 ms
6,248 KB
testcase_23 AC 3 ms
4,376 KB
testcase_24 AC 1 ms
4,376 KB
testcase_25 AC 17 ms
4,664 KB
testcase_26 AC 33 ms
7,384 KB
testcase_27 AC 26 ms
6,284 KB
testcase_28 AC 38 ms
8,208 KB
testcase_29 AC 21 ms
5,228 KB
testcase_30 AC 19 ms
4,836 KB
testcase_31 AC 32 ms
7,328 KB
testcase_32 AC 23 ms
5,576 KB
testcase_33 AC 72 ms
13,964 KB
testcase_34 AC 72 ms
13,960 KB
testcase_35 AC 71 ms
14,016 KB
testcase_36 AC 72 ms
13,940 KB
testcase_37 AC 72 ms
14,012 KB
testcase_38 AC 71 ms
13,960 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

const LIMIT: usize = 9;
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();

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