QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#358788#6300. Best Carry Player 2Djangle162857WA 1ms3572kbC++201.6kb2024-03-20 00:23:472024-03-20 00:23:48

Judging History

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

  • [2024-03-20 00:23:48]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3572kb
  • [2024-03-20 00:23:47]
  • 提交

answer

#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N = 25;
int t, K, L;
int a10[N];
int s, k;
int a[N];
int dp[N][N];
signed main()
{
	a10[0] = 1;
	for (int i = 1; i < 18; i++)
		a10[i] = a10[i - 1] * 10;
	cin >> t;
	while (t--) {  //补充一个特判
		cin >> s >> k;
		if (k == 0) {
			string ss;
			while (s >= 1) {
				int res = s % 10;
				s = s / 10;
				if (res == 9)
					ss.push_back('0');
				else {
					ss.push_back('1');
					break;
				}
			}
			for (int i = ss.size() - 1; i >= 0; i--) {
				cout << ss[i];
			}
			cout << endl;
			continue;
		}
		L = 0;
		for (int i = 0; i < 18; i++) {
			a[i] = s % 10;
			if (a[i])
				L = i;
			s /= 10;
		}
		if (a[0] == 9) {
			int tt = 0;
			while (a[tt] == 9)
				tt++;
			if (tt == k) {
				cout << 1 << endl;
				continue;
			}
		}
		L = max(L, k - 1);
		for (int i = 0; i <= 18; i++)
			for (int j = 1; j <= 18; j++)
				dp[i][j] = -1;
		// dp[0][0]=0;
		if (a[0])
			dp[0][1] = 10 - a[0];
		for (int i = 1; i <= L; i++) {
			if (a[i])
				dp[i][1] = a10[i] * (10 - a[i]);
			for (int j = 2; j <= i + 1; j++) {
				if (a[i] > 0) {
					for (int j1 = 0; j1 <= i - 2; j1++) {
						if ((a[j1] + a[j1 + 1] != 18) && ~dp[j1][j - 1])
							dp[i][j] = dp[j1][j - 1];
					}
				}
				if (~dp[i - 1][j - 1])
					dp[i][j] = dp[i - 1][j - 1] + a10[i] * (9 - a[i]);
			}
		}
		int ans = 0;
		for (int i = 0; i < 18; i++) {
			if (~dp[i][k] && a[i] + a[i + 1] != 18) {
				if (dp[i][k] == 0)
					dp[i][k]++;
				cout << dp[i][k] << endl;
				ans = 1;
				break;
			}
		}
		if (!ans)
			cout << -1 << endl;
	}
	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 3572kb

input:

4
12345678 0
12345678 5
12345678 18
990099 5

output:

1
54322
999999999987654322
9910

result:

ok 4 lines

Test #2:

score: -100
Wrong Answer
time: 0ms
memory: 3556kb

input:

21
999990000099999 0
999990000099999 1
999990000099999 2
999990000099999 3
999990000099999 4
999990000099999 5
999990000099999 6
999990000099999 7
999990000099999 8
999990000099999 9
999990000099999 10
999990000099999 11
999990000099999 12
999990000099999 13
999990000099999 14
999990000099999 15
999...

output:

100000
10000
1000
100
10
1
900001
9900001
99900001
999900001
9999900001
9999910000
9999901000
9999900100
9999900010
9999900001
9000009999900001
99000009999900001
999000009999900001
-1
000000000000000000

result:

wrong answer 11th lines differ - expected: '10000000001', found: '9999900001'