結果

問題 No.1085 桁和の桁和
ユーザー 沙耶花沙耶花
提出日時 2020-06-19 22:01:52
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 39 ms / 2,000 ms
コード長 993 bytes
コンパイル時間 2,306 ms
コンパイル使用メモリ 199,672 KB
実行使用メモリ 10,496 KB
最終ジャッジ日時 2024-04-24 10:02:31
合計ジャッジ時間 3,894 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 37 ms
10,112 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 5 ms
5,376 KB
testcase_14 AC 12 ms
6,016 KB
testcase_15 AC 25 ms
9,344 KB
testcase_16 AC 25 ms
9,344 KB
testcase_17 AC 12 ms
6,144 KB
testcase_18 AC 7 ms
5,376 KB
testcase_19 AC 22 ms
8,704 KB
testcase_20 AC 23 ms
8,704 KB
testcase_21 AC 15 ms
6,656 KB
testcase_22 AC 20 ms
8,192 KB
testcase_23 AC 4 ms
5,376 KB
testcase_24 AC 2 ms
5,376 KB
testcase_25 AC 13 ms
6,272 KB
testcase_26 AC 25 ms
9,600 KB
testcase_27 AC 21 ms
8,192 KB
testcase_28 AC 29 ms
10,368 KB
testcase_29 AC 15 ms
6,912 KB
testcase_30 AC 15 ms
6,656 KB
testcase_31 AC 25 ms
9,344 KB
testcase_32 AC 16 ms
7,424 KB
testcase_33 AC 38 ms
10,496 KB
testcase_34 AC 38 ms
10,496 KB
testcase_35 AC 38 ms
10,368 KB
testcase_36 AC 38 ms
10,368 KB
testcase_37 AC 38 ms
10,496 KB
testcase_38 AC 39 ms
10,368 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 1000000000LL



int main(){
	
	string S;
	cin>>S;
	
	vector<vector<int>> dp(S.size()+1,vector<int>(9,0));
	dp[0][0] = 1;
	
	for(int i=0;i<S.size();i++){
		for(int j=0;j<9;j++){
			if(dp[i][j]==0)continue;
			char c = S[i];
			if(c=='?'){
				for(int k=0;k<10;k++){
					int nj = (j * 10 + k)%9;
					dp[i+1][nj] = mod(dp[i+1][nj] + dp[i][j]);
				}
			}
			else{
				int t = c-'0';
				dp[i+1][(j*10 + t)%9] = mod(dp[i+1][(j*10+t)%9] + dp[i][j]);
			}
		}
	}
	
	int D;
	cin>>D;
	if(D==0){
		bool f = true;
		for(int i=0;i<S.size();i++){
			if(S[i]!='0'&&S[i]!='?'){
				f=false;
			}
		}
		if(f)cout<<1<<endl;
		else cout<<0<<endl;
	}
	else{
		int ans = dp.back()[D%9];
		if(D==9){
			bool f = true;
			for(int i=0;i<S.size();i++){
				if(S[i]!='0'&&S[i]!='?'){
					f=false;
				}
			}
			if(f)ans = mod(ans-1);
		}
		cout<<ans<<endl;
	}
	
	return 0;
}
0