QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#103257#6300. Best Carry Player 2Nerovix#WA 3ms3392kbC++202.1kb2023-05-04 21:35:072023-05-04 21:35:09

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-05-04 21:35:09]
  • 评测
  • 测评结果:WA
  • 用时:3ms
  • 内存:3392kb
  • [2023-05-04 21:35:07]
  • 提交

answer

#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define db double
#define pint pair<int,int>
#define mk make_pair
#define pb push_back
#define eb emplace_back
#define ins insert
#define fi first
#define se second
#define For(x, y, z) for(int x = (y); x <= (z); x++)
#define Rep(x, y, z) for(int x = (y); x >= (z); x--)
using namespace std;
const int MAXN = 55;
char buf[1 << 12], *pp1 = buf, *pp2 = buf, nc;
inline char gc() {
    return (pp1 == pp2) && (pp2 = (pp1 = buf) + fread(buf, 1, 1 << 12, stdin), pp1 == pp2) ? EOF : *pp1++;
}
inline ll read() {
    ll x = 0, ny = 1;
    for(; nc = gc(), (nc < 48 || nc > 57) && nc != EOF; ) 
        if(nc == '-') ny = -1;
    if(nc < 0) return nc;
    x = nc ^ 48;
    for(; nc = gc(), (nc >= 48 && nc <= 57 && nc != EOF); )
        x = (x << 3) + (x << 1) + (nc ^ 48);
    return x * ny;
}
int a[MAXN];
ll f[MAXN][MAXN][2], Fpow[MAXN];
inline void Solve() {
    memset(a, 0, sizeof(a));
    ll x = read(), k = read(), len = 0;
    while(x) a[++len] = x % 10, x /= 10;
    if(k == 0) {
        int tmp = len + 1;
        For(i, 1, len + 9) if(a[i] != 9) {
            tmp = i;
            break;
        }
        cout << Fpow[tmp - 1] << '\n';
    } else{
        memset(f, 0x3f,sizeof(f));
        f[0][0][0] = 0;
        For(i, 1, max(len + 1, k)) {
            For(j, 0, k) For(t, 0, 1){
                if(a[i] + t <= 9) f[i][j][0] = min(f[i - 1][j][t], f[i][j][0]);
                if(a[i] + t >= 10) f[i][j + 1][1] = min(f[i - 1][j][t], f[i][j + 1][1]);
                else if(10 - t - a[i] <= 9) 
                    f[i][j + 1][1] = min(f[i - 1][j][t] + (10 - t - a[i]) * Fpow[i - 1], f[i][j + 1][1]);
            }
        } 
        cout << min(f[max(len + 1, k)][k][0], f[max(len + 1, k)][k][1]) << '\n';
    }
}
int main() {
    // freopen(".in", "r", stdin);
    // freopen(".out", "w", stdout);
    Fpow[0] = 1;
    For(i, 1, 18) Fpow[i] = Fpow[i - 1] * 10;
    for(int t = read(); t--; ) {
        Solve();
    }    
    return 0;
}
/*
4
12345678 0
12345678 5
12345678 18
990099 5
*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 3ms
memory: 3344kb

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: 2ms
memory: 3392kb

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
-4889313184910721217
1000000000000000000

result:

wrong answer 20th lines differ - expected: '99999999999999999900000000000000000', found: '-4889313184910721217'