QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#292991 | #6300. Best Carry Player 2 | zxzxzxq# | WA | 1ms | 3500kb | C++17 | 1.7kb | 2023-12-28 19:10:55 | 2023-12-28 19:10:55 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
using i64 = long long ;
using i128 = __int128;
const int N = 1e5 + 10;
i64 n, k;
i128 pw[40];
string s;
i128 calc()
{
i128 res = 0;
for(i128 i = 0;i < s.size();i ++)
res = res * 10 + (s[i] - '0');
return res;
}
// i128 read()
// {
// i128 x = 0, f = 1;
// char ch = getchar();
// while (ch < '0' || ch > '9')
// {
// if (ch == '-') f = -1;
// ch = getchar();
// }
// while(ch >= '0' && ch <= '9')
// {
// x = x * 10 + (ch - '0');
// ch = getchar();
// }
// return x * f;
// }
void print(i128 x)
{
if (x < 0)
{
putchar('-');
x = -x;
}
if (x > 9)
print(x / 10);
putchar('0' +( x % 10));
}
void solve()
{
cin >> s >> k;
n = calc();
if (k == 0)
{
bool _9 = true;
for(int i = 0;i < s.size() && _9;i ++)
if(s[i] != '9')
_9 = false;
if (_9) print(pw[s.size()]), puts("");
else puts("1");
return ;
}
reverse(s.begin(), s.end());
for(i128 i = 0;i < s.size();i ++)
{
i64 st = i + k;
i128 aim = n % pw[st] / pw[i];
if (s[st - 1] == '9' && st != s.size() || aim == 0 || s[i] == '0') continue;
i128 ans = pw[st] - aim * pw[i];
print(ans);
puts("");
return ;
}
puts("-1");
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
pw[0] = 1;
for(i128 i = 1;i < 40;i ++)
pw[i] = pw[i - 1] * 10;
int T = 1;
cin >> T;
while(T --)
solve();
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3436kb
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: 3500kb
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 100000000000000 910000 901000 900100 900010 900001 9900001 99900001 999900001 9999900001 9999910000 9999901000 9999900100 9999900010 9999900001 9000009999900001 99000009999900001 999000009999900001 99999999999999999900000000000000000 1000000000000000000
result:
wrong answer 1st lines differ - expected: '100000', found: '1'