QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#778924 | #6300. Best Carry Player 2 | wangshengzhe | WA | 0ms | 3616kb | C++14 | 2.3kb | 2024-11-24 16:47:52 | 2024-11-24 16:47:52 |
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 __int128
const int INF = 1e36;
#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[40][20][2];
int num[40];
int a[20];
inline static void read(int& n) {
int x = 0, f = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-') f = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
x = (x << 1) + (x << 3) + (ch ^ 48);
ch = getchar();
}
n = x * f;
}
inline static void print(int n) {
if (n < 0) {
putchar('-');
n *= -1;
}
if (n > 9) print(n / 10);
putchar(n % 10 + '0');
}
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, 36) 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) {
print(num[i - 1]);
cout << endl;
return;
}
}
}
rep(i, 1, 36)
{
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, 36) {
ans = min(ans, min(dp[i][m][1], dp[i][m][0]));
}
print(ans);
cout << endl;
return;
}
signed main()
{
int t = 1;
read(t);
while (t--)
{
read(x);
read(m);
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3616kb
input:
4 12345678 0 12345678 5 12345678 18 990099 5
output:
1 1000000000000000042420637374017961984 1000000000000000042420637374017961984 1000000000000000042420637374017961984
result:
wrong answer 2nd lines differ - expected: '54322', found: '1000000000000000042420637374017961984'