QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#117363 | #6300. Best Carry Player 2 | memset0 | WA | 0ms | 3380kb | C++20 | 1.9kb | 2023-07-01 02:14:34 | 2023-07-01 02:14:35 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using ull = unsigned long long;
const int N = 25, n = 18;
int T, k, a[N];
ull x, f[N], dp[N][N];
inline void chkmin(ull &x, ull y) {
if (y < x) x = y;
}
inline ull pick(int l, int r) {
ull s = 0;
for (int i = l; i <= r; i++) {
s = s * 10 + a[i];
}
return s;
}
int main() {
#ifdef memset0
freopen("1.in", "r", stdin);
#endif
cin >> T;
f[0] = 1;
for (int i = 1; i <= n + 1; i++) f[i] = f[i - 1] * 10;
while (T--) {
memset(a, 0, sizeof(a));
memset(dp, 63, sizeof(dp));
cin >> x >> k;
for (int i = 1; i <= n; i++) {
a[i] = x % 10;
x /= 10;
}
if (k == 0) {
ull y = 1;
for (int i = 1; i <= n + 1; i++)
if (a[i] < 9) {
cout << y << endl;
break;
} else {
y *= 10;
}
continue;
}
for (int i = 1; i <= n; i++)
if (a[i]) {
int d = 0;
while (a[i + d + 1] == 9) ++d;
dp[i + d][1 + d] = f[i - 1] * (10 - a[i]);
}
for (int i = 1; i <= n; i++)
for (int j = 0; j < k; j++)
if (dp[i][j] != dp[0][0]) {
for (int v = i + 1; v <= n; v++) {
int x = v == i + 1 ? a[v] + 1 : a[v];
if (!x) continue;
int d = 0;
while (a[v + d + 1] == 9) ++d;
chkmin(dp[v + d][j + d + 1], dp[i][j] + f[v - 1] * (10 - x));
// fprintf(stderr, "dp[%d][%d] -> dp[%d][%d](%d) : %llu + %llu * %d : %llu\n", i, j, v + d, j + d + 1, d, dp[i][j], f[v - 1], 10 - x, dp[v + d][j + d + 1]);
}
}
// for (int i = 1; i <= n; i++)
// for (int j = 1; j <= k; j++)
// if (dp[i][j] != dp[0][0]) {
// printf("dp[%d][%d] = %llu\n", i, j, dp[i][j]);
// }
ull ans = dp[0][0];
for (int i = 1; i <= n; i++) {
chkmin(ans, dp[i][k]);
}
cout << ans << endl;
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3376kb
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: 3380kb
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 4557430888798830399 1000000000000000000
result:
wrong answer 20th lines differ - expected: '99999999999999999900000000000000000', found: '4557430888798830399'