QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#627095 | #6300. Best Carry Player 2 | TokaiZaopen# | WA | 1ms | 3580kb | C++20 | 2.0kb | 2024-10-10 14:43:37 | 2024-10-10 14:43:37 |
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 = -1;
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)
{
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)
{
if (ans == -1)
ans = res;
else
ans = min(ans, res);
}
}
cout << ans << '\n';
}
/*
4
12345678 0
12345678 5
12345678 18
990099 5
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 3580kb
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'