QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#778819 | #6300. Best Carry Player 2 | Anneliese# | WA | 1ms | 3600kb | C++20 | 1.8kb | 2024-11-24 16:25:23 | 2024-11-24 16:25:24 |
Judging History
answer
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<string>
#include<cstring>
#include<cmath>
#include<set>
#include<map>
#include<vector>
#include<queue>
#include<unordered_map>
#include<stack>
#include<numeric>
using namespace std;
#define int long long
const int INF = 0X3f3f3f3f3f3f3f3f;
#define rep(i, a, b) for(int i = a;i <= b;i++)
#define pre(i, a, b) for(int i = a;i >= b;i--)
int x, m;
int dp[20][20][2];
int num[20];
int a[20];
void solve()
{
memset(dp, 0x3f, sizeof dp);
memset(a, 0, sizeof a);
int cnt = 0;
while (x)
{
a[++cnt] = x % 10;
x /= 10;
}
num[0] = 1;
rep(i, 1, 18) num[i] = num[i - 1] * 10;
dp[0][0][0] = 0;
int p = max(cnt, m);
if (m == 0)
{
rep(i, 1, cnt + 1)
{
if (a[i] != 9) {
cout << num[i - 1] << endl;
return;
}
}
}
rep(i, 1, 18)
{
rep(k, 0, m)
{
if (a[i] + 1 < 10)
{
dp[i][k][0] = min(dp[i - 1][k][1], dp[i - 1][k][0]);
}
else
{
dp[i][k][0] = dp[i - 1][k][0];
}
if (k != 0)
{
if (a[i] != 0) dp[i][k][1] = min((10 - a[i] - 1) * num[i - 1] + dp[i - 1][k - 1][1], (10 - a[i]) * num[i - 1] + dp[i - 1][k - 1][0]);
else dp[i][k][1] = (10 - a[i] - 1) * num[i - 1] + dp[i - 1][k - 1][1];
}
}
}
int ans = INF;
rep(i, cnt, 18) {
ans = min(ans, min(dp[i][m][1], dp[i][m][0]));
}
cout << ans << endl;
return;
}
signed main()
{
int t = 1;
cin >> t;
while (t--)
{
cin >> x >> m;
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3600kb
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: 1ms
memory: 3580kb
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:
100000 10000 1000 100 10 1 900001 9900001 99900001 999900001 10000000001 9999910000 9999901000 9999900100 9999900010 9999900001 9000009999900001 99000009999900001 999000009999900001 4557430888798830399 1000000000000000000
result:
wrong answer 20th lines differ - expected: '99999999999999999900000000000000000', found: '4557430888798830399'