QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#627151 | #6300. Best Carry Player 2 | TokaiZaopen# | WA | 1ms | 3608kb | C++20 | 2.6kb | 2024-10-10 14:58:58 | 2024-10-10 14:58:59 |
Judging History
answer
#include <bits/stdc++.h>
#define int ll
using ll = unsigned long long;
// #define MING_LE
const int mod = 998244353;
const int inf = 1e18;
using namespace std;
int a[40];
int b[40];
int c[40];
__int128_t ten[40];
void out(__int128_t x);
void solve();
signed main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int __ = 1;
cin >> __;
ten[0] = 1;
for (int i = 1; i <= 36; i++)
{
ten[i] = ten[i - 1] * 10;
}
while (__--)
solve();
return 0;
}
void solve()
{
int now;
int n, m;
n = 0;
cin >> now >> m;
for (int i = 0; i <= 36; i++)
{
a[i] = 0;
b[i] = 0;
}
while (now)
{
b[n] = now % 10;
now /= 10;
n++;
}
for (int i = 0; i <= 36; i++)
{
a[i] = 1;
for (int j = i + 1; j <= 36; j++)
{
if (b[j] != 9)
break;
a[i]++;
}
}
__int128_t ans = -1;
for (int i = 0; i <= n; i++)
{
for (int j = 0; j <= 36; j++)
c[j] = b[j];
int p = i;
int buffer = 0;
__int128_t res = 0;
while (buffer < m && p <= 36)
{
if (buffer + a[p] <= m && c[p] > 0)
{
buffer += a[p];
int flag = 0;
for (int j = p; j < p + a[p]; j++)
{
res += (10ULL - c[j] - flag) * ten[j];
flag = 1;
}
p += a[p];
c[p] += flag;
}
else
p++;
}
#ifdef MING_LE
cout << i << " ";
out(res);
cout << " " << buffer << '\n';
// cout << i << " " << buffer << '\n';
// for (int i = n; i >= 0; i--)
// cout << c[i];
// cout << '\n';
#endif
if (buffer == m)
{
if (ans < 0)
ans = res;
ans = min(ans, res);
}
}
if (ans < 0)
cout << "-1\n";
else
{
out(ans);
cout << '\n';
}
}
void out(__int128_t x)
{
stack<int> sck;
while (x > 0)
{
sck.push(x % 10);
x /= 10;
}
if (sck.empty())
{
cout << "0";
return;
}
while (!sck.empty())
{
cout << sck.top();
sck.pop();
}
}
/*
4
12345678 0
12345678 5
12345678 18
990099 5
*/
/*
1
99999999999999999 1
*/
/*
1
1000000000000000000 18
*/
详细
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 3608kb
input:
4 12345678 0 12345678 5 12345678 18 990099 5
output:
0 54322 999999999987654322 9910
result:
wrong answer 1st lines differ - expected: '1', found: '0'