結果
| 問題 |
No.1085 桁和の桁和
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-06-19 22:13:29 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,251 bytes |
| コンパイル時間 | 1,573 ms |
| コンパイル使用メモリ | 172,016 KB |
| 実行使用メモリ | 13,568 KB |
| 最終ジャッジ日時 | 2024-07-23 00:14:10 |
| 合計ジャッジ時間 | 3,066 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 32 WA * 3 |
ソースコード
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
using ll = long long ;
using P = pair<int,int> ;
using pll = pair<long long,long long>;
constexpr int INF = 1e9;
constexpr long long LINF = 1e17;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979323846;
int main(){
string t;
cin >> t;
int d;
cin >> d;
int n = t.size();
if(d==0){
bool zero = true;
rep(i,n){
if('1' <= t[i] && t[i] <= '9') zero = false;
}
if(zero) cout << 1 << endl;
else cout << 0 << endl;
return 0;
}
vector<vector<ll>> dp(n+1,vector<ll>(9,0));
dp[0][0] = 1;
for(int i=0;i<n;i++){
bool q = false;
int td = t[i] - '0';
if(td < 0 || 9 < td) q = true;
if(!q){
for(int j=0;j<9;j++){
dp[i+1][(10*j+td)%9] += dp[i][j];
dp[i+1][(10*j+td)%9] %= MOD;
}
}else{
for(int j=0;j<9;j++){
rep(k,10){
dp[i+1][(10*j+k)%9] += dp[i][j];
dp[i+1][(10*j+k)%9] %= MOD;
}
}
}
}
d %= 9;
cout << dp[n][d] << endl;
return 0;
}