結果

問題 No.1085 桁和の桁和
ユーザー snrnsidysnrnsidy
提出日時 2021-08-19 21:05:05
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 37 ms / 2,000 ms
コード長 696 bytes
コンパイル時間 2,125 ms
コンパイル使用メモリ 194,972 KB
実行使用メモリ 11,520 KB
最終ジャッジ日時 2024-04-21 00:19:06
合計ジャッジ時間 4,079 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 35 ms
11,264 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 1 ms
5,376 KB
testcase_13 AC 5 ms
5,376 KB
testcase_14 AC 11 ms
6,400 KB
testcase_15 AC 22 ms
10,368 KB
testcase_16 AC 22 ms
10,240 KB
testcase_17 AC 11 ms
6,656 KB
testcase_18 AC 7 ms
5,376 KB
testcase_19 AC 21 ms
9,600 KB
testcase_20 AC 21 ms
9,472 KB
testcase_21 AC 13 ms
7,424 KB
testcase_22 AC 19 ms
8,960 KB
testcase_23 AC 4 ms
5,376 KB
testcase_24 AC 2 ms
5,376 KB
testcase_25 AC 12 ms
6,912 KB
testcase_26 AC 22 ms
10,496 KB
testcase_27 AC 19 ms
9,088 KB
testcase_28 AC 25 ms
11,520 KB
testcase_29 AC 15 ms
7,552 KB
testcase_30 AC 14 ms
7,296 KB
testcase_31 AC 22 ms
10,240 KB
testcase_32 AC 16 ms
8,064 KB
testcase_33 AC 37 ms
11,520 KB
testcase_34 AC 36 ms
11,520 KB
testcase_35 AC 35 ms
11,520 KB
testcase_36 AC 36 ms
11,392 KB
testcase_37 AC 36 ms
11,392 KB
testcase_38 AC 35 ms
11,392 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

const long long int MOD = 1e9 + 7;

long long int dp[100005][10];

int f(int x)
{
	while(x >= 10)
	{
		int y = x/10 + x%10;
		x = y;
	}

	return x;
}
int main(void)
{
	cin.tie(0);
	ios::sync_with_stdio(false);

	string s;
	int n,d;

	cin >> s;
	cin >> d;

	dp[0][0] = 1;

	n = s.length();
	
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<10;j++)
		{
			if(s[i]=='?')
			{
				for(int k=0;k<10;k++)
				{
					int x = f(j + k);
					dp[i+1][x] += dp[i][j];
					dp[i+1][x]%=MOD;
				}
			}
			else
			{
				int k = s[i] - '0';
				int x = f(j + k);
				dp[i+1][x] += dp[i][j];
				dp[i+1][x]%=MOD;			
			}
		}
	}

	cout << dp[n][d] << '\n';

	return 0;
}
0