QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#288030 | #6300. Best Carry Player 2 | Jacka1# | WA | 1ms | 3620kb | C++14 | 1.8kb | 2023-12-21 16:22:00 | 2023-12-21 16:22:01 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
int main() {
cin.tie(0)->sync_with_stdio(false);
int T;
cin >> T;
while (T--) {
[]() {
i64 x;
int k;
cin >> x >> k;
using i128 = __int128;
vector<i128> bit(38), pw(38);
pw[1] = 1;
for (int i = 1; i < 38; i++) {
bit[i] = x % 10;
if (i > 1) pw[i] = pw[i - 1] * 10;
x /= 10;
}
const i128 inf = 1e37;
vector<vector<array<i128, 2>>> dp(38, vector<array<i128, 2>>(k + 2, {inf, inf}));
dp[0][0][0] = 0;
for (int i = 1; i < 38; i++) {
for (int j = 0; j <= k; j++) {
for (int l : {0, 1}) {
if (bit[i] + l < 10) {
dp[i][j][0] = min(dp[i][j][0], dp[i - 1][j][l]);
}
if (10 - l - bit[i] < 10 and j >= 1) {
dp[i][j][1] = min(dp[i][j][1], dp[i - 1][j - 1][l] + pw[i] * (10 - l - bit[i]));
}
}
}
}
[&](i128 v) {
if (v == 0) {
if (bit[1] != 9) cout << 1 << '\n';
else cout << -1 << '\n';
return;
}
if (v == inf) {
cout << -1 << '\n';
return;
}
vector<int> nums;
while (v) {
nums.emplace_back((int) (v % 10));
v /= 10;
}
for (auto it = nums.rbegin(); it != nums.rend(); it++) {
cout << *it;
}
cout << '\n';
}(min(dp[37][k][0], dp[37][k][1]));
}();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3508kb
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: 3620kb
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:
-1 10000 1000 100 10 1 900001 9900001 99900001 999900001 10000000001 9999910000 9999901000 9999900100 9999900010 9999900001 9000009999900001 99000009999900001 999000009999900001 99999999999999999900000000000000000 -1
result:
wrong answer 1st lines differ - expected: '100000', found: '-1'