QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#152271#6300. Best Carry Player 2chen_zexingWA 1ms3696kbC++172.1kb2023-08-27 22:08:502023-08-27 22:08:50

Judging History

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

  • [2023-08-27 22:08:50]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3696kb
  • [2023-08-27 22:08:50]
  • 提交

answer

#pragma GCC optimize("Ofast,unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#define li __int128_t
li dp[35][20][2];
void output(li x){
    if(!x) return;
    output(x/10);
    printf("%d",int(x%10));
}
int main() {
    int T = 1, kase = 0;
    cin >> T;
    while (T--) {
        long long n;
        int k;
        scanf("%lld%d",&n,&k);
        if(!k){
            li base=1;
            for(int i=1;;i++,base*=10){
                int r=n%10;
                n/=10;
                if(r!=9){
                    output(base);
                    puts("");
                    break;
                }
            }
            continue;
        }
        memset(dp,-1,sizeof(dp));
        dp[0][0][0]=0;
        li base=1;
        for(int i=1;;i++,base*=10){
            int r=n%10;
            n/=10;
            for(int j=0;j<=k;j++)
                for(int l=0;l<2;l++) {
                    if (!l){
                        dp[i][j][l] = dp[i - 1][j][l];
                        if(dp[i-1][j][1]!=-1&&r!=9){
                            if(dp[i][j][l]==-1||dp[i-1][j][1]<dp[i][j][l]) dp[i][j][l]=dp[i-1][j][1];
                        }
                    }
                    else if (j) {
                        int nd = 10 - r;
                        if (dp[i - 1][j - 1][0] != -1) dp[i][j][l] = dp[i - 1][j - 1][0] + base * nd;
                        if (dp[i - 1][j - 1][1] != -1) {
                            if (dp[i][j][l] == -1 || dp[i - 1][j - 1][1] + base * (nd - 1) < dp[i][j][l])
                                dp[i][j][l] = dp[i - 1][j - 1][1] + base * (nd - 1);
                        }
                    }
                    /*
                    if(dp[i][j][l]!=-1){
                        cout<<i<<" "<<j<<" "<<l<<" ";
                        output(dp[i][j][l]),puts("");
                    }
                     */
                }
            if(dp[i][k][0]!=-1){
                output(dp[i][k][0]);
                puts("");
                break;
            }
        }
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3696kb

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

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
10000000000
9999910000
9999901000
9999900100
9999900010
9999900001
9000009999900001
99000009999900001
999000009999900001
900000000000000000
1000000000000000000

result:

wrong answer 11th lines differ - expected: '10000000001', found: '10000000000'