結果
| 問題 |
No.1085 桁和の桁和
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-06-19 22:11:25 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 960 bytes |
| コンパイル時間 | 2,767 ms |
| コンパイル使用メモリ | 192,636 KB |
| 最終ジャッジ日時 | 2025-01-11 06:31:18 |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 32 WA * 3 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
constexpr int mod = 1000000007;
constexpr int M = 100010;
long long dp[M][9];
int main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
string T; cin >> T;
int D; cin >> D;
if (D == 0) {
for (auto &c: T) {
if (c != '0' && c != '?') {
cout << 0 << "\n";
return 0;
}
}
cout << 1 << "\n";
return 0;
}
dp[0][0] = 1;
int N = T.size();
for (int i = 0; i < N; i++) {
if (T[i] != '?') {
for (int j = 0; j < 9; j++) {
dp[i+1][(j+T[i]-'0')%9] = dp[i][j];
}
} else {
for (int j = 0; j < 9; j++) {
dp[i][j] %= mod;
for (int k = 0; k < 10; k++) {
dp[i+1][(j+k)%9] += dp[i][j];
}
}
}
}
cout << dp[N][D%9] % mod << "\n";
return 0;
}