QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#389566#7996. 报数 IVO_start#WA 20ms75384kbC++142.0kb2024-04-14 15:50:072024-04-14 15:50:07

Judging History

你现在查看的是最新测评结果

  • [2024-04-14 15:50:07]
  • 评测
  • 测评结果:WA
  • 用时:20ms
  • 内存:75384kb
  • [2024-04-14 15:50:07]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define MAX (int)2e5+100
#define mod 1000000007
int k, m;
string s;
ll dp[1100][9100];//位数 数

bool ju(int x)
{
	for (int i = 0; i < k - 1; i++) {
		int tmp = 0;
		while (x) {
			tmp += x % 10;
			x /= 10;
		}
		x = tmp;
	}
	if (x == m)
		return 1;
	return 0;
}

int main()
{
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int i, j;
	int T;
	cin >> T;
	for (i = 0; i <= 9; i++)
		dp[1][i] = 1;
	for (i = 2; i <= 1000; i++) {
		ll tmp = 0;
		for (j = 0; j <= 9 * i; j++) {
			if (j > 9) {
				tmp -= dp[i - 1][j - 9];
			}
			tmp += dp[i - 1][j];
			tmp %= mod;
			dp[i][j] = tmp;
			//for (int p = j; p >= 0 && p >= j - 9; p--) {
			//	dp[i][j] += dp[i - 1][p];
			//	dp[i][j] %= mod;
			//}
			
		}
	}
	//for (i = 1; i <= 5; i++) {
	//	for (j = 0; j <= 10; j++) {
	//		cout << dp[i][j] << ' ';
	//	}
	//	cout << '\n';
	//}
	while (T--) {
		cin >> s >> k >> m;
		if (k >= 4)
			k = 4;
		if (m > 9000) {
			printf("0\n");
			continue;
		}
		//for (i = 0; i <= s[s.size() - 1] - '0'; i++)
		//	dp[0][i] = 1;
		ll res = 0;
		int p;
		int sum = 0;
		for (i = 0; i < s.size(); i++) {
			sum += (s[i] - '0');
		}
		
		//if (ju(sum))
		//	res++;
		//cout << sum << ' ';
		for (i = 0; i <= 9000; i++) {
			if (ju(i)) {
				if (sum - (s[s.size() - 1] - '0') >= i - 9 && sum - (s[s.size() - 1] - '0') <= i)
					res++;
				//cout << i << '\n';
				int ssum = i;
				//res += dp[s.size() - 1][m];
				//cout << res << '\n';
				for (j = 0; j < s.size(); j++) {
					int len = s.size();
					for (p = 0; p < s[j] - '0'; p++) {
						if (ssum - p < 0)
							break;
						res += dp[len - 1 - j][ssum - p];
						//res--;
						//cout << len - 1 - j << ' ' << ssum - p << ' ' << res << '\n';
						res %= mod;
					}
					ssum -= (s[j] - '0');
					if (ssum < 0)
						break;
					//cout << res << '\n';
				}
			}
		}
		cout << res << '\n';
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 18ms
memory: 75336kb

input:

2
114 1 5
514 2 10

output:

8
10

result:

ok 2 lines

Test #2:

score: -100
Wrong Answer
time: 20ms
memory: 75384kb

input:

5
114 1 5
514 2 10
114514 3 7
1919810 2 13
1145141919810114514191981011451419198101145141919810114514191981011451419198101145141919810114514191981011451419198101145141919810 1 79

output:

8
10
9691
94
977307084

result:

wrong answer 3rd lines differ - expected: '12724', found: '9691'