QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#627112 | #6300. Best Carry Player 2 | TokaiZaopen# | WA | 0ms | 3664kb | C++20 | 2.1kb | 2024-10-10 14:47:36 | 2024-10-10 14:47:36 |
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[20];
int b[20];
int c[20];
int ten[20];
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 <= 18; i++)
{
ten[i] = ten[i - 1] * 10LL;
}
while (__--)
solve();
return 0;
}
void solve()
{
int now;
int n, m;
n = 0;
cin >> now >> m;
for (int i = 0; i <= 18; i++)
{
a[i] = 0;
b[i] = 0;
}
while (now)
{
b[n] = now % 10;
now /= 10;
n++;
}
for (int i = 0; i <= 18; i++)
{
a[i] = 1;
for (int j = i + 1; j <= 18; j++)
{
if (b[j] != 9)
break;
a[i]++;
}
}
int ans = 0;
ans = (~ans);
for (int i = 0; i <= n; i++)
{
for (int j = 0; j <= 18; j++)
c[j] = b[j];
int p = i;
int buffer = 0;
int res = 0;
while (buffer < m && p <= 18)
{
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 << " " << buffer << '\n';
for (int i = n; i >= 0; i--)
cout << c[i];
cout << '\n';
#endif
if (buffer == m)
{
ans = min(ans, res);
}
}
if (ans == (~0ULL))
cout << "-1\n";
else
cout << ans << '\n';
}
/*
4
12345678 0
12345678 5
12345678 18
990099 5
*/
/*
1
99999999999999999 1
*/
详细
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3664kb
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'