結果

問題 No.1085 桁和の桁和
ユーザー snow39
提出日時 2020-06-19 22:14:21
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 41 ms / 2,000 ms
コード長 1,514 bytes
コンパイル時間 932 ms
コンパイル使用メモリ 97,132 KB
実行使用メモリ 15,104 KB
最終ジャッジ日時 2024-11-06 17:35:03
合計ジャッジ時間 2,741 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 35
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <tuple>
#define mkp make_pair
#define mkt make_tuple
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define all(v) v.begin(),v.end()
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;
template<class T> void chmin(T &a,const T &b){if(a>b) a=b;}
template<class T> void chmax(T &a,const T &b){if(a<b) a=b;}
void add(ll &a,ll b){
a=(a+b)%MOD;
}
void mul(ll &a,ll b){
a%=MOD;b%=MOD;
a=a*b%MOD;
}
const int L=1e6;
int getDigitSum(int val){
int res=0;
while(val>0){
res+=val%10;
val/=10;
}
return res;
}
int main(){
cin.tie(0);
ios::sync_with_stdio(false);
string S;
cin>>S;
int N=S.size();
int D;
cin>>D;
/*vector<int> dp(L+1,0);
for(int i=0;i<=9;i++) dp[i]=i;
for(int i=10;i<=L;i++){
int now=i;
while(now>=10){
now=getDigitSum(now);
}
dp[i]=now;
}*/
vector<vector<ll>> dp(N+1,vector<ll> (10,0));
dp[0][0]=1;
for(int i=0;i<N;i++) for(int j=0;j<=9;j++){
if(dp[i][j]==0) continue;
if(S[i]!='?'){
int nex=j+S[i]-'0';
if(nex>=10) nex=nex%10+1;
add(dp[i+1][nex],dp[i][j]);
}else{
for(int k=0;k<=9;k++){
int nex=j+k;
if(nex>=10) nex=nex%10+1;
add(dp[i+1][nex],dp[i][j]);
}
}
}
cout<<dp[N][D]<<endl;
return 0;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0