結果

問題 No.1085 桁和の桁和
ユーザー phsplsphspls
提出日時 2023-01-12 00:19:40
言語 Rust
(1.77.0)
結果
WA  
実行時間 -
コード長 1,025 bytes
コンパイル時間 863 ms
コンパイル使用メモリ 150,156 KB
実行使用メモリ 12,452 KB
最終ジャッジ日時 2023-08-24 04:39:00
合計ジャッジ時間 3,720 ms
ジャッジサーバーID
(参考情報)
judge15 / 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 2 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 WA -
testcase_10 AC 1 ms
4,376 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 4 ms
4,380 KB
testcase_14 AC 11 ms
4,380 KB
testcase_15 AC 23 ms
6,584 KB
testcase_16 AC 23 ms
6,540 KB
testcase_17 AC 12 ms
4,380 KB
testcase_18 AC 6 ms
4,380 KB
testcase_19 AC 21 ms
5,956 KB
testcase_20 AC 1 ms
4,380 KB
testcase_21 AC 14 ms
4,492 KB
testcase_22 AC 19 ms
5,732 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 1 ms
4,384 KB
testcase_25 AC 12 ms
4,380 KB
testcase_26 AC 24 ms
6,740 KB
testcase_27 AC 19 ms
5,704 KB
testcase_28 AC 27 ms
7,312 KB
testcase_29 AC 15 ms
4,740 KB
testcase_30 AC 13 ms
4,392 KB
testcase_31 AC 23 ms
6,580 KB
testcase_32 AC 16 ms
5,036 KB
testcase_33 AC 52 ms
12,360 KB
testcase_34 AC 51 ms
12,388 KB
testcase_35 AC 51 ms
12,384 KB
testcase_36 AC 52 ms
12,416 KB
testcase_37 AC 51 ms
12,388 KB
testcase_38 AC 52 ms
12,452 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
warning: variable does not need to be mutable
  --> Main.rs:21:9
   |
21 |     let mut cnt = t.iter().filter(|&&c| c == '?').count();
   |         ----^^^
   |         |
   |         help: remove this `mut`
   |
   = note: `#[warn(unused_mut)]` on by default

warning: 1 warning emitted

ソースコード

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();

    if d == 0 {
        if t.iter().any(|&c| c != '0' && c != '?') {
            println!("0");
        } else {
            println!("1");
        }
        return;
    }
    let summary = t.iter().filter(|&&c| c != '?').map(|&c| c as usize - '0' as usize).sum::<usize>() % 9;
    let mut 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;
    println!("{}", dp[cnt][d]);
}
0