QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#694096#6300. Best Carry Player 2ucup-team2179#WA 1ms3844kbC++201.6kb2024-10-31 17:16:002024-10-31 17:16:01

Judging History

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

  • [2024-10-31 17:16:01]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3844kb
  • [2024-10-31 17:16:00]
  • 提交

answer

#include<bits/stdc++.h>
#define int long long
#define ll long long
#define pii pair<int, int>
using namespace std;
int dp[20][20][2], a[20], p[20];
void solve(){
    int x, k, n = 0;
    cin >> x >> k;
    memset(a, 0, sizeof a);
    for (n = 1; x; n++){
        a[n] = x % 10;
        x /= 10;
    }
    n = max(n, k);
    if(k == 0){
        string x = "1";
        for(int i = 1; i <= n; i++){
            if(a[i] != 9)
                break;
            x = x + '0';
        }
        cout << x << '\n';
        return;
    }
    for(int i = 0; i <= k; i++)
        dp[0][i][0] = dp[0][i][1] = 1e18;
    p[1] = 1;
    dp[0][0][0] = 0;
    for(int i = 1; i <= n; i++){
        p[i + 1] = p[i] * 10;
        for(int j = 0; j <= k; j++)
            dp[i][j][0] = dp[i][j][1] = 1e18;
        for (int j = 0; j <= k; j++){
            for(int x : {0ll, min(9ll, 10 - a[i]), 9 - a[i]}){
                if(x + a[i] >= 10) dp[i][j+1][1] = min(dp[i][j+1][1], dp[i-1][j][0] + x * p[i]);
                else
                    dp[i][j][0] = min(dp[i][j][0], dp[i - 1][j][0] + x * p[i]);
                if(x + a[i] >= 9)
                    dp[i][j + 1][1] = min(dp[i][j + 1][1], dp[i - 1][j][1] + x * p[i]);
                else
                    dp[i][j][0] = min(dp[i][j][0], dp[i - 1][j][1] + x * p[i]);
            }
        }
    }
    x = min(dp[n][k][0], dp[n][k][1]);
    if(x < 1e18) cout << x << '\n';
    else cout << "-1\n";
}
signed main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int t;
    cin >> t;
    while(t--) solve();
    return 0;
}

詳細信息

Test #1:

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

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: 0ms
memory: 3556kb

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

result:

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