QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#179919#6300. Best Carry Player 2ucup-team045#WA 1ms5824kbC++202.5kb2023-09-15 13:27:542023-09-15 13:27:55

Judging History

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

  • [2023-09-15 13:27:55]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:5824kb
  • [2023-09-15 13:27:54]
  • 提交

answer

#include<iostream>
#include<cstring>
#include<vector>
using namespace std;
using LL = long long;
char buf[1 << 23], *p1 = buf, *p2 = buf, obuf[1 << 23], *O = obuf;
#define getchar() (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 23, stdin), p1 == p2) ? EOF: *p1++)

template<typename T>
void read(T &x){
    x = 0;
    T w = 1;
    char ch = getchar();
    while(ch < '0' || ch > '9'){
        if (ch == '-') w = -1;
        ch = getchar();
    }
    while(ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
    x *= w;
}

template<typename T, typename... Args> 
void read(T &first, Args& ... args) {
    read(first);
    read(args...);
}

template<typename T>
void write(T x){
    if (x < 0) {putchar('-'); x = -x;}
    if (x > 9) write(x / 10);
    putchar(x % 10 + '0');
}

template<typename T, typename... Args> 
void write(T first, Args ... args){
    write(first);
    write(args...);
}

__int128_t dp[20][2], ndp[20][2];

int main(){

#ifdef LOCAL
    freopen("data.in", "r", stdin);
    freopen("data.out", "w", stdout);
#endif

    __int128_t pow10[37];
    pow10[0] = 1;
    for(int i = 1; i <= 36; i++)
        pow10[i] = pow10[i - 1] * 10;

    const __int128_t INF = 1e37;

    int T;
    read(T);
    while(T--){
        __int128_t x; int k;
        read(x, k);
        if (k == 0){
            if (x % 10 == 9){
                puts("-1");
            }
            else{
                puts("1");
            }
            continue;
        }
        for(int i = 0; i <= k; i++)
            dp[i][0] = dp[i][1] = INF;
        dp[0][0] = 0;
        for(int i = 0; i <= 36; i++, x /= 10){
            for(int j = 0; j <= k; j++)
                ndp[j][0] = ndp[j][1] = INF;
            for(int j = 0; j <= k; j++){
                for(int t = 0; t < 2; t++){
                    int cur = x % 10 + t;
                    if (cur == 10){
                        if (j + 1 <= k){
                            ndp[j + 1][1] = min(ndp[j + 1][1], dp[j][t]);
                        }
                    }
                    else{
                        ndp[j][0] = min(ndp[j][0], dp[j][t]);
                        if (cur >= 1){
                            ndp[j + 1][1] = min(ndp[j + 1][1], dp[j][t] + pow10[i] * (10 - cur));
                        }
                    }
                }
            }
            swap(dp, ndp);
        }
        write(min(dp[k][0], dp[k][1]));
        putchar('\n');
    }

}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 5528kb

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

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'