QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#745829 | #6300. Best Carry Player 2 | dezex# | WA | 0ms | 3644kb | C++20 | 2.6kb | 2024-11-14 11:50:16 | 2024-11-14 11:50:16 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e18;
const int N = 20;
ll dp[N][N][2], p[N];
int digit[N];
int main()
{
ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
int T, cnt_end_zero, k;
ll x;
p[0] = 1;
for (int i = 1; i <= 18; i++)
p[i] = 10 * p[i - 1];
cin >> T;
while (T--)
{
cin >> x >> k;
if (k == 0)
{
cout << 1 << endl;
continue;
}
cnt_end_zero = 0;
while (x % 10 == 0)
{
cnt_end_zero++;
x /= 10;
}
for (int i = 0; i < N; i++)
for (int j = 0; j < N; j++)
dp[i][j][0] = dp[i][j][1] = INF;
dp[0][0][0] = 0;
for (int i = 1; i < N; i++)
{
digit[i] = x % 10;
x /= 10;
// cout << i << " " << digit[i] << endl;
}
for (int i = 1; i < N; i++)
{
dp[i][0][0] = 0;
for (int j = 1; j <= i; j++)
{
if (dp[i - 1][j][0] < INF)
dp[i][j][0] = min(dp[i][j][0], dp[i - 1][j][0]);
if (digit[i] != 9 && dp[i - 1][j][1] < INF)
dp[i][j][0] = min(dp[i][j][0], dp[i - 1][j][1]);
// if (i == 2 && j == 2)
// {
// cout << "test" << endl;
// cout << dp[i - 1][j - 1][1] << " " << (10 - digit[i] - 1) * p[i - 1] << endl;
// }
// if (i == 5 && j == 4)
// {
// cout << "test" << endl;
// cout << dp[i - 1][j - 1][1] << endl;
// cout << (10 - digit[i] - 1) * p[i - 1] << endl;
// cout << "-----------" << endl;
// }
if (dp[i - 1][j - 1][1] < INF)
dp[i][j][1] = min(dp[i][j][1], dp[i - 1][j - 1][1] + (10 - digit[i] - 1) * p[i - 1]);
if (digit[i] != 0 && dp[i - 1][j - 1][0] < INF)
dp[i][j][1] = min(dp[i][j][1], dp[i - 1][j - 1][0] + (10 - digit[i]) * p[i - 1]);
}
}
// cout << dp[1][0][1] << endl;
// for (int i = 1; i <= 5; i++)
// cout << "==" << i << dp[i][i][1] << endl;
// cout << dp[2][1][1] << endl;
// cout << dp[4][3][1] << endl;
// cout << dp[5][4][1] << endl;
// cout << dp[6][5][1] << endl;
cout << dp[N - 1][k][0];
for (int i = 1; i <= cnt_end_zero; i++)
cout << 0;
cout << endl;
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3644kb
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: 0ms
memory: 3564kb
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 10000 1000 100 10 1 900001 9900001 99900001 999900001 10000000001 9999910000 9999901000 9999900100 9999900010 9999900001 9000009999900001 99000009999900001 999000009999900001 99999999999999999900000000000000000 1
result:
wrong answer 1st lines differ - expected: '100000', found: '1'