QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#129470#6300. Best Carry Player 2OFforest_1273WA 1ms3720kbC++141.6kb2023-07-22 19:53:052023-07-22 19:57:03

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-07-22 19:57:03]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3720kb
  • [2023-07-22 19:53:05]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define ll long long
void ckmin(ll &x, ll y) {x = min(x, y);}
const int N = 19;
int k,bit[N];
char str[N+1];
ll shi[N],dp[N][N][2];
void solve(int id) {
	scanf("%s%d", str + 1, &k);
	memset(bit, 0, sizeof bit);
	int n = strlen(str + 1);
	int m = n;
	int zero = 0;
	while (m >= 1 && str[m] == '0') m --, zero ++;
//	memset(dp, 0x3f, sizeof dp); // ?? 太小 ?? 
	for (int i = 0; i < N; i ++)
		for (int j = 0; j < N; j ++)
			dp[i][j][0] = dp[i][j][1] = 1e18-1;
	for (int i = 1, j = m; i <= m; i ++, j --)
		bit[i] = str[j] - '0';
	dp[0][0][0] = 0;
	for (int i = 1; i < N; i ++) {
		int a = bit[i];
		for (int j = 0; j <= k; j ++) {
			// 第 i 位 没有进位  i - 1 not
			ckmin(dp[i][j][0],dp[i - 1][j][0]);
			// i - 1 yes
			if (a != 9)ckmin(dp[i][j][0], dp[i - 1][j][1]); 
			if (j) {
				ll need = 10 - a;
				if(a)ckmin(dp[i][j][1], need * shi[i - 1] + dp[i - 1][j - 1][0]);
				// i - 1 yes
				need = 9 - a;
				ckmin(dp[i][j][1], need * shi[i - 1] + dp[i - 1][j - 1][1]);
			}
		}
	}
	ll ans = min({dp[N - 1][k][0],dp[N-1][k][1]});
	if (ans==0) {
		vector<int> ans;
		for (int i = n; i >= 1; i --) {
			if (i == 1 || str[i] != '9') {ans.push_back(1);break;}
			ans.push_back(0);
		}
		reverse(ans.begin(), ans.end());
		for (auto p : ans)
			cout << p;
		puts("");
		return; 
	}
	printf("%lld", (long long)ans);
	for (int i = 1; i <= zero; i ++)
		printf("0");
	puts("");
}
int main() {
	shi[0] = 1;
	for (int i = 1; i < N; i ++)shi[i] = shi[i - 1] * 10;
	int T;
	cin >> T;
	for (int i = 1; i <= T; i ++)solve(i);
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 1ms
memory: 3720kb

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
10000000001
9999910000
9999901000
9999900100
9999900010
9999900001
9000009999900001
99000009999900001
999000009999900001
99999999999999999900000000000000000
100000000000000000

result:

wrong answer 21st lines differ - expected: '1000000000000000000', found: '100000000000000000'