QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#291972#6300. Best Carry Player 2QwertyPi#WA 1ms3788kbC++171.1kb2023-12-27 14:59:332023-12-27 14:59:33

Judging History

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

  • [2023-12-27 14:59:33]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3788kb
  • [2023-12-27 14:59:33]
  • 提交

answer

#include <bits/stdc++.h>

#define int long long
#define all(a) (a).begin(), (a).end()
#define sz(a) (int) (a).size()
#define forn(i, n) for(int i = 0; i < (n); i++)

using namespace std;

int carryLam(__int128_t a, __int128_t b){
    __int128_t c = 0, res = 0;
    while(a > 0 || b > 0){
        int a0 = a % 10, b0 = b % 10; a /= 10; b /= 10;
        if (a0 + b0 + c >= 10) c = 1, res++;
        else c = 0;
    }
    return res;
}

int x, k; 
__int128_t ans = -1;
void test(__int128_t y){
    int c = carryLam(x, y);
    if(c == k){
        ans = ans == -1 || y < ans ? y : ans;
    }
}

void solve(){
    ans = -1;
    cin >> x >> k;
    test(1);
    __int128_t r = 0, pw10 = 1;
    for(int b = 0; b < 36; b++){
        pw10 *= 10;
        test(pw10 - x % pw10);
    }
    if(ans == -1){
        cout << -1 << '\n';
    }else{
        string r; while(ans > 0) r.push_back('0' + ans % 10), ans /= 10; reverse(all(r));
        cout << r << '\n';
    }
}

int32_t main(){
    cin.tie(0); cout.tie(0)->sync_with_stdio(false);
    int t = 1;
    cin >> t;
    while(t--){
        solve();
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 3788kb

input:

4
12345678 0
12345678 5
12345678 18
990099 5

output:

1
54322
999999999987654322
-1

result:

wrong answer 4th lines differ - expected: '9910', found: '-1'