QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#361508#6300. Best Carry Player 2recollector#WA 0ms3836kbC++202.0kb2024-03-23 10:51:062024-03-23 10:51:06

Judging History

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

  • [2024-03-23 10:51:06]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3836kb
  • [2024-03-23 10:51:06]
  • 提交

answer

#include <cstdio>
#include <cstring>
#include <cctype>
#include <algorithm>
#include <iostream>
#include <queue>
typedef long long LL;
using namespace std;
inline LL read() {
    LL num = 0 ,f = 1; char c = getchar();
    while (!isdigit(c)) f = c == '-' ? -1 : f ,c = getchar();
    while (isdigit(c)) num = (num << 1) + (num << 3) + (c ^ 48) ,c = getchar();
    return num * f;
}
const int N = 20 ,INF = 0x3f3f3f3f;
int f[N][N][2] ,k ,pre[N][N][2];
LL x;
inline void fuling_solve() {
    memset(f ,0x3f ,sizeof(f));
    memset(pre ,0 ,sizeof(pre));
    x = read() ,k = read();
    vector <int> nums(1);
    while (x) nums.emplace_back(x % 10) ,x /= 10;
    if (k == 0) {
    	string res;
    	for (int i = 1; i < (int)nums.size(); i++) if (nums[i] == 9) res += '0'; else {
    		res += '1'; break;
		}
		if (res.back() != '1') res += '1';
		reverse(res.begin() ,res.end());
		cout << res << endl;
		return ;
	}
    while ((int)nums.size() < k + 1) nums.emplace_back(0);
    f[0][0][0] = 1;
    for (int i = 0; i < (int)nums.size(); i++)
        for (int j = 0; j <= k; j++)
            for (int p = 0; p <= 1; p++)
                if (f[i][j][p] != INF) {
                    for (int now = 0; now <= 9; now++) {
                        int q = now + nums[i + 1] + p >= 10;
                        if (f[i + 1][j + q][q] > now) {
                        	f[i + 1][j + q][q] = now;
							pre[i + 1][j + q][q] = p;
						}
                    }
                }
    int st = f[(int)nums.size() - 1][k][0] < f[(int)nums.size() - 1][k][1] ? 0 : 1;
    string str;
    for (int i = (int)nums.size() - 1; i >= 1; i--) {
        int q = f[i][k][st];
        str += q + '0';
		int tmp = k;
		k -= st;
        st = pre[i][tmp][st];
    }
    reverse(str.begin() ,str.end());
    while (str.size() && str.back() == '0') str.pop_back();
    if (str.size() == 0u) str += '1';
    reverse(str.begin() ,str.end());
	cout << str << endl;
}
signed main() {
    int t = read();
    while (t--) fuling_solve();
    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 3628kb

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: 3836kb

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
10000000000000
1000000000000
100000000000
10000000000
10000010000
10000001000
10000000100
10000000010
10000000001
9999910000
9999901000
9999900100
9999900010
9999900001
9000009999900001
99000009999900001
999000009999900001
oooooooooooooooooo
1000000000000000000

result:

wrong answer 3rd lines differ - expected: '1000', found: '10000000000000'