結果
| 問題 |
No.1085 桁和の桁和
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2023-01-04 23:16:11 |
| 言語 | Rust (1.83.0 + proconio) |
| 結果 |
AC
|
| 実行時間 | 63 ms / 2,000 ms |
| コード長 | 1,443 bytes |
| コンパイル時間 | 22,035 ms |
| コンパイル使用メモリ | 377,616 KB |
| 実行使用メモリ | 14,080 KB |
| 最終ジャッジ日時 | 2024-11-28 03:23:47 |
| 合計ジャッジ時間 | 19,850 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 35 |
ソースコード
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);
}