QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#681540 | #6300. Best Carry Player 2 | karito# | WA | 0ms | 3832kb | C++20 | 1.2kb | 2024-10-27 09:55:14 | 2024-10-27 09:55:15 |
Judging History
answer
#include <iostream>
#include <string>
using namespace std;
void work();
int main()
{
ios::sync_with_stdio(false);
int t;
cin >> t;
while (t--)
work();
return 0;
}
void work()
{
string s, t;
int k;
cin >> s >> k;
for (int i = s.size(); i <= 40; i++)
t.push_back('0');
t += s;
bool bef = 0;
int cnt = 0;
string ans;
for (int i = 0; i < t.size(); i++)
ans.push_back('0');
for (int i = t.size() - 1; i >= 0; i--)
{
int x = t[i] - '0';
if (bef)
x++;
if (cnt < k)
{
int tmp = 10 - x;
if (tmp >= 10)
tmp = 0;
x += tmp;
ans[i] = '0' + tmp;
}
if (x >= 10)
{
cnt++;
bef = true;
}
else
bef = false;
}
for (int i = t.size() - 2; i >= 0; i--)
{
if (cnt == k)
break;
if (ans[i] < '9' && ans[i + 1]>'0')
{
ans[i + 1] = '0';
ans[i]++;
cnt--;
}
}
if (cnt != k)
{
cout << "-1\n";
return;
}
bool flag = false;
for (char i : ans)
{
if (flag || i != '0')
{
flag = true;
cout << i;
}
}
if (!flag)
{
cout << '1';
for (int i = t.size() - 1; i >= 0; i--)
if (t[i] == '9')
cout << '0';
}
cout << '\n';
return;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3644kb
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: 3832kb
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:
10000000000 10000 1000 100 10 1 900001 9900001 99900001 999900001 10999910000 9999910000 9999901000 9999900100 9999900010 9999900001 9000009999900001 99000009999900001 999000009999900001 99999999999999999900000000000000000 1000000000000000000
result:
wrong answer 1st lines differ - expected: '100000', found: '10000000000'