QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#277283#6300. Best Carry Player 2shiqiaqiayaWA 1ms3656kbC++201.5kb2023-12-06 17:22:052023-12-06 17:22:05

Judging History

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

  • [2023-12-06 17:22:05]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3656kb
  • [2023-12-06 17:22:05]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'

void QAQ() {
    int k;
    string x;
    cin >> x >> k;

    reverse(x.begin(), x.end());
    int n = x.size();

    vector<int> a(n + 1 + k);

    for (int i = 1; i <= n; i++) {
        a[i] = x[i - 1] - '0';
    }

    vector dp(n + 1 + k, vector(k + 1, vector<__int128>(2, 4e18)));
    dp[0][0][0] = 0;

    __int128 tmp = 1;

    for (int i = 1; i <= n + k; i++) {
        for (int j = 0; j <= k; j++) {
            if (a[i] + 1 < 10) {
                dp[i][j][0] = min(dp[i][j][0], dp[i - 1][j][1]);
            }
            dp[i][j][0] = min(dp[i][j][0], dp[i - 1][j][0]);
            if (j >= 1) {
                dp[i][j][1] = min(dp[i][j][1], dp[i - 1][j - 1][1] + tmp * (9 - a[i]));
                dp[i][j][1] = min(dp[i][j][1], dp[i - 1][j - 1][0] + tmp * (10 - a[i]));
            }
        }
        tmp *= 10;
    }

    int ans = min(dp[n + k][k][0], dp[n + k][k][1]);

    if (ans == 0) {
        tmp = 1;
        for (int i = 1; i <= n + k; i++) {
            if (a[i] + 1 < 10) {
                cout << (int)tmp << "\n";
                return;
            }
            tmp *= 10;
        }
    } else if (ans == 4e18) {
        cout << "-1\n";
    } else {
        cout << ans << "\n";
    }
}

signed main() {
    cin.tie(0) -> sync_with_stdio(0);
    int t = 1;
    cin >> t;

    while (t--) {
        QAQ();
    }
}

詳細信息

Test #1:

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

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

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

result:

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