QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#778920#6300. Best Carry Player 2Anneliese#WA 0ms3596kbC++202.3kb2024-11-24 16:47:122024-11-24 16:47:12

Judging History

你现在查看的是最新测评结果

  • [2024-11-24 16:47:12]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3596kb
  • [2024-11-24 16:47:12]
  • 提交

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: 3596kb

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'