結果
| 問題 | No.1085 桁和の桁和 | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2021-08-19 21:05:05 | 
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 34 ms / 2,000 ms | 
| コード長 | 696 bytes | 
| コンパイル時間 | 2,024 ms | 
| コンパイル使用メモリ | 192,484 KB | 
| 最終ジャッジ日時 | 2025-01-23 23:00:20 | 
| ジャッジサーバーID (参考情報) | judge1 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 4 | 
| other | AC * 35 | 
ソースコード
#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;
}
            
            
            
        