結果
| 問題 |
No.1085 桁和の桁和
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-06-19 22:13:52 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 34 ms / 2,000 ms |
| コード長 | 960 bytes |
| コンパイル時間 | 2,488 ms |
| コンパイル使用メモリ | 192,900 KB |
| 最終ジャッジ日時 | 2025-01-11 06:35:20 |
|
ジャッジサーバーID (参考情報) |
judge3 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 35 |
ソースコード
#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;
bool zero = true;
for (auto &c: T) {
if (c != '0' && c != '?') {
zero = false;
}
}
if (D == 0) {
cout << zero << "\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];
}
}
}
}
if (zero) dp[N][0]--;
cout << dp[N][D%9] % mod << "\n";
return 0;
}