結果

問題 No.1085 桁和の桁和
ユーザー Y17Y17
提出日時 2020-06-19 22:07:57
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 93 ms / 2,000 ms
コード長 836 bytes
コンパイル時間 1,454 ms
コンパイル使用メモリ 163,440 KB
実行使用メモリ 44,544 KB
最終ジャッジ日時 2024-04-24 10:02:49
合計ジャッジ時間 4,220 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 22 ms
34,688 KB
testcase_01 AC 21 ms
34,816 KB
testcase_02 AC 22 ms
34,944 KB
testcase_03 AC 23 ms
34,816 KB
testcase_04 AC 93 ms
44,032 KB
testcase_05 AC 22 ms
34,816 KB
testcase_06 AC 23 ms
34,688 KB
testcase_07 AC 22 ms
34,816 KB
testcase_08 AC 23 ms
34,944 KB
testcase_09 AC 23 ms
34,688 KB
testcase_10 AC 22 ms
34,816 KB
testcase_11 AC 22 ms
34,688 KB
testcase_12 AC 22 ms
34,944 KB
testcase_13 AC 28 ms
35,840 KB
testcase_14 AC 38 ms
38,272 KB
testcase_15 AC 58 ms
42,880 KB
testcase_16 AC 60 ms
43,008 KB
testcase_17 AC 39 ms
38,528 KB
testcase_18 AC 31 ms
36,736 KB
testcase_19 AC 55 ms
42,240 KB
testcase_20 AC 57 ms
42,240 KB
testcase_21 AC 44 ms
39,424 KB
testcase_22 AC 54 ms
41,344 KB
testcase_23 AC 25 ms
35,328 KB
testcase_24 AC 24 ms
35,072 KB
testcase_25 AC 43 ms
39,040 KB
testcase_26 AC 60 ms
43,136 KB
testcase_27 AC 53 ms
41,472 KB
testcase_28 AC 66 ms
44,416 KB
testcase_29 AC 46 ms
40,064 KB
testcase_30 AC 44 ms
39,424 KB
testcase_31 AC 58 ms
42,752 KB
testcase_32 AC 49 ms
40,320 KB
testcase_33 AC 87 ms
44,288 KB
testcase_34 AC 86 ms
44,544 KB
testcase_35 AC 88 ms
44,288 KB
testcase_36 AC 90 ms
44,416 KB
testcase_37 AC 92 ms
44,416 KB
testcase_38 AC 88 ms
44,416 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

#define int long long
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

#define MOD 1000000007

string s;
int d;
int memo[100010][20][2];

int dp(int i, int num, int az){
	if(i == s.size()){
		if(az) return d == 0 ? 1 : 0;
		return (num == 0 ? 9 : num) == d ? 1 : 0;
	}
	if(memo[i][num][az] != -1) return memo[i][num][az];
	int ans = 0;
	if(s[i] != '?') ans = dp(i+1, (num*10+s[i]-'0') % 9, az && s[i] == '0');
	else{
		for(int k = 0;k < 10;k++){
			ans = (ans + dp(i+1, (num*10+k)% 9, az && k == 0))%MOD;
		}
	}
	return memo[i][num][az] = ans;
}

signed main(){
	cin >> s >> d;

	memset(memo, -1, sizeof(memo));

	cout << dp(0, 0, true) << endl; 

	return 0;
}
0