QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#627599 | #6300. Best Carry Player 2 | TokaiZaopen# | WA | 0ms | 3660kb | C++20 | 2.9kb | 2024-10-10 16:26:42 | 2024-10-10 16:26:42 |
Judging History
answer
#include <bits/stdc++.h>
#define int ll
using ll = unsigned long long;
// #define MING_LE
const int mod = 998244353;
const __int128_t inf = 1e36;
using namespace std;
int a[40];
int b[40];
__int128_t dp[40][40][2];
__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]++;
}
}
for (int i = 0; i <= 36; i++)
{
for (int j = 0; j <= 36; j++)
{
for (int k = 0; k <= 1; k++)
dp[i][j][k] = inf;
}
}
dp[0][0][0] = 0;
for (int i = 0; i <= 36; i++)
{
for (int j = 0; j <= 36; j++)
{
for (int k = 0; k <= 1; k++)
{
if (k == 0 && i > 0)
dp[i][j][k] = min(dp[i][j][k], min(dp[i - 1][j][0], dp[i - 1][j][1]));
__int128_t buffer = 0;
int flag = k;
if (b[i] == 0 && flag == 0)
continue;
buffer += (10 - flag - b[i]) * ten[i];
// for (int p = i; p < i + a[i] + (a[i] == 0 ? flag : 0); p++)
// {
// buffer += (10 - flag - b[p]) * ten[p];
// flag = 1;
// }
dp[i + a[i]][j + a[i]][1] = min(dp[i][j][k] + buffer, dp[i + a[i]][j + a[i]][1]);
}
}
}
__int128_t ans = inf;
for (int i = 0; i <= 36; i++)
for (int k = 0; k <= 1; k++)
{
ans = min(ans, dp[i][m][k]);
#ifdef MING_LE
cout << i << " " << k << " ";
out(dp[i][m][k]);
cout << '\n';
#endif
}
if (ans < inf)
{
out(ans);
cout << '\n';
}
else
cout << "-1\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
*/
/*
1
990099990099 5
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3660kb
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'