QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#209984#6300. Best Carry Player 2therehello#WA 1ms3516kbC++201.4kb2023-10-10 21:06:402023-10-10 21:06:40

Judging History

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

  • [2023-10-10 21:06:40]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3516kb
  • [2023-10-10 21:06:40]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using i64 = long long;

void print(__int128_t x) {
    string res = "";
    while (x) {
        res += x % 10 + '0';
        x /= 10;
    }
    reverse(res.begin(), res.end());
    cout << res << "\n";
}

void solve() {
    i64 x, k;
    cin >> x >> k;

    vector<int> a(40);
    for (int i = 0; i < 20; ++i) {
        a[i] = x % 10;
        x /= 10;
    }
    if (k == 0) {
        __int128_t p = 1;
        for (int i = 0; i < 19; ++i, p *= 10) {
            if (a[i] != 9) {
                break;
            }
        }
        print(p);
        return;
    }
    __int128_t ans = (((__int128_t)1) << 127) - 1;
    for (int i = 0; i < 19; ++i) {
        auto b = a;
        int m = k;
        __int128_t y = 0, p = 1;
        for (int j = 0; j < 35; ++j, p *= 10) {
            if (j < i) continue;
            if (b[j] <= 9) {
                if (b[j] != 0 && m > 0) {
                    y += p * (10 - b[j]);
                    b[j + 1] += 1;
                    --m;
                }
            } else {
                --m;
                b[j + 1] += 1;
            }
        }
        if (m == 0) {
            ans = min(ans, y);
        }
    }

    print(ans);
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int t = 1;
    cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}

詳細信息

Test #1:

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

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

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

result:

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