QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#250848 | #6300. Best Carry Player 2 | DepletedPrism# | WA | 1ms | 3424kb | C++17 | 1.9kb | 2023-11-13 19:40:23 | 2023-11-13 19:40:24 |
Judging History
answer
// C
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using i128 = __int128;
i128 xpw10(int x, int l) { // x * (10 ** l)
static vector<i128> pw10{1};
int n = (int)pw10.size();
if (l >= n) {
pw10.resize(l + 1);
for (int i = n; i <= l; ++i)
pw10[i] = 10 * pw10[i - 1];
}
return x * pw10[l];
}
void print(i128 x) {
if (x > 0) {
print(x / 10);
cout << char('0' + x % 10);
}
}
int main() {
ios::sync_with_stdio(false), cin.tie(nullptr);
int ti;
cin >> ti;
while (ti--) {
LL x; int k;
cin >> x >> k;
vector<int> a;
for (LL i = x; i > 0; i /= 10)
a.push_back(i % 10);
int n = a.size(), m = n + k;
a.resize(m + 1, 0);
vector<int> nl(m + 1);
nl[0] = (a[0] == 0);
for (int i = 1; i <= m; ++i)
nl[i] = (a[i] == 9)? nl[i - 1] + 1: 0;
// for (auto v: a) cout << v << " ";
// cout << endl;
i128 ans = (i128(1) << 126) - 1;
if (k == 0) {
for (int i = 0; i <= m; ++i) if (a[i] < 9) {
ans = xpw10(1, i);
break;
}
} else {
for (int p = 0; p < n; ++p) {
auto b = a;
i128 y = 0;
int cur = k;
for (int i = p; i < m; ++i) if (a[i] > 0) {
int j = i; // [i, j]: j - i + 1,
while (j + 1 < m && cur - (j + 1 + nl[j + 2] - i + 1) >= 0)
++j;
if (cur - (j + nl[j + 1] - i + 1) >= 0) {
j += nl[j + 1];
cur -= (j - i + 1);
// cout << cur << endl;
// cout << "[" << i << ", " << j << "]" << endl;
y += xpw10(10 - b[i], i);
for (int l = i + 1; l <= j; ++l)
y += xpw10(9 - b[l], l);
++b[j + 1], i = j;
if (cur == 0) break;
}
}
if (cur == 0)
ans = min(ans, y);
}
}
print(ans), cout << '\n';
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 3424kb
input:
4 12345678 0 12345678 5 12345678 18 990099 5
output:
1 54322 999999999987654322 9901
result:
wrong answer 4th lines differ - expected: '9910', found: '9901'