QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#291972 | #6300. Best Carry Player 2 | QwertyPi# | WA | 1ms | 3788kb | C++17 | 1.1kb | 2023-12-27 14:59:33 | 2023-12-27 14:59:33 |
Judging History
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'