QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#594293#6300. Best Carry Player 2shiqiaqiaya#WA 1ms3728kbC++173.0kb2024-09-27 21:02:172024-09-27 21:02:18

Judging History

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

  • [2024-09-27 21:02:18]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3728kb
  • [2024-09-27 21:02:17]
  • 提交

answer

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/priority_queue.hpp>
#include <ext/rope>
using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;
#define int long long
using ll = long long;
mt19937_64 rd(time(0));
template <class K, class C = less<>> using paring_heap = __gnu_pbds::priority_queue<K, C>;
template <class K> using rb_tree = tree<K, null_type, less<>, rb_tree_tag, tree_order_statistics_node_update>;
template <class T, class ... A> void debug(const T & t, const A & ... a) { cerr << "[" << t, ((cerr << ", " << a), ...), cerr << "]\n"; }
const ll mod = [](bool n) { return n ? 998244353 : 1e9 + 7; } (1);

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

    reverse(n.begin(), n.end());

    while (n.size() <= 32) {
        n += '0';
    }

    n = " " + n;
    auto print = [&](auto && self, __int128 t) -> void {
        if (t >= 10) {
            self(self, t / 10);
        }
        cout << (int)(t % 10);
    };

    vector dp(k + 1, vector<array<__int128, 2>>(n.size(), array<__int128, 2>{numeric_limits<__int128>::max(), numeric_limits<__int128>::max()}));
    dp[0][0][0] = 0;
    if (k == 0) {
        __int128 base = 1;
        for (int i = 1; i < n.size(); i++, base *= 10) {
            if (n[i] != '9') {
                print(print, base);
                cout << "\n";
                return;
            }
        }
        cout << "-1\n";
        return;
    }
    __int128 base = 1, ans = numeric_limits<__int128>::max();
    for (int i = 1; i < n.size(); i++, base *= 10) {
        for (int j = 0; j < 10; j++) {
            for (int tk = 0; tk <= k; tk++) {
                for (auto c : {0, 1}) {
                    if (dp[tk][i - 1][c] == numeric_limits<__int128>::max()) continue;
                    if (n[i] - '0' + j + c >= 10) {
                        for (int ti = i + 1; ti < n.size(); ti++) {
                            if (tk + ti - i > k) break;
                            if (n[ti] != '9') {
                                dp[tk + ti - i][ti - 1][1] = min(dp[tk + ti - i][ti - 1][1], dp[tk][i - 1][c] + j * base);
                                if (tk + ti - i == k) {
                                    ans = min(ans, dp[tk + ti - i][ti - 1][1]);
                                }
                                break;
                            }
                        }
                    } else {
                        dp[tk][i][0] = min(dp[tk][i][0], dp[tk][i - 1][c] + j * base);
                        if (tk == k) {
                            ans = min(ans, dp[tk][i][0]);
                        }
                    }
                }
            }
        }
    }
    if (ans == numeric_limits<__int128>::max()) {
        cout << "-1\n";
    } else {
        print(print, ans);
        cout << "\n";
    }
}

signed main() {
    cin.tie(0) -> sync_with_stdio(0);
    int t = 1;
    cin >> t;
    for (cout << fixed << setprecision(12); t--; QAQ());
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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

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

result:

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