QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#293778 | #6300. Best Carry Player 2 | SunlightZero | WA | 0ms | 3768kb | C++14 | 2.7kb | 2023-12-29 18:57:48 | 2023-12-29 18:57:49 |
Judging History
answer
#include <iostream>
#include <string>
#include <cstdlib>
#include <cstring>
#include <deque>
using namespace std;
bool is_carry[55];
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
size_t t;
cin >> t;
for (size_t _ = 1; _ <= t; _++)
{
string x_str;
size_t k;
cin >> x_str >> k;
if (k == 0)
{
deque<char> ans;
for (auto it = x_str.rbegin(); it != x_str.rend(); ++it)
{
if (*it == '9')
{
ans.push_front('0');
}
else
{
break;
}
}
ans.push_front('1');
for (char ch: ans)
{
cout << ch;
}
cout << '\n';
continue;
}
size_t n_post_zero = 0;
bool post_end = false;
memset(is_carry, 0, sizeof(is_carry));
deque<unsigned> dq;
for (auto it = x_str.rbegin(); it != x_str.rend(); ++it)
{
char ch = *it;
if (!post_end)
{
if (ch == '0')
{
n_post_zero++;
}
else
{
post_end = true;
dq.push_back(ch - '0');
}
}
else
{
dq.push_back(ch - '0');
}
}
while (dq.size() <= 50)
{
dq.push_back(0);
}
int i = 0, j;
size_t cnt = 0;
for (j = 0; j < (int) dq.size(); j++)
{
cnt++;
if (cnt == k)
{
if (dq[j + 1] == 9)
{
do {
i++;
cnt--;
} while (dq[i] == 0);
}
else
{
break;
}
}
}
string ans = "";
bool is_post_zero = true;
for (int k = j; k >= i; k--)
{
if (is_post_zero && dq[k] == 9)
{
continue;
}
else
{
is_post_zero = false;
ans += '0' + (9u + (i == k) - dq[k]);
}
}
for (int k = i - 1; k >= 0; k--)
{
ans += '0';
}
while (n_post_zero--)
{
ans += '0';
}
cout << ans << '\n';
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3768kb
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: 3560kb
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 0000 000 00 0 900001 9900001 99900001 999900001 99999000010000000000 9999910000 9999901000 9999900100 9999900010 9999900001 9000009999900001 99000009999900001 999000009999900001 99999999999999999900000000000000000 1000000000000000000
result:
wrong answer 2nd lines differ - expected: '10000', found: '0000'