QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#220859 | #6300. Best Carry Player 2 | Young | WA | 1ms | 3444kb | C++14 | 3.1kb | 2023-10-20 21:53:46 | 2023-10-20 21:53:46 |
Judging History
answer
#include<bits/stdc++.h>
#define int long long
using namespace std;
string s,s1,ss;
string a[50];
string s2[50];
void solve(){
int x,kk,minn=-1;
cin>>x>>kk;
s="";
while(x>0){
int g=x%10;
x/=10;
s+=('0'+g);
}
if(kk==0){
int cnt=0;
for(int i=0;i<s.length();i++){
if(s[i]!='9'){
break;
}
cnt++;
}
cout<<1;
for(int i=1;i<=cnt;i++) cout<<0;
cout<<'\n';return ;
}
for(int i=1;i<=20;i++){
s+='0';
}
// cout<<s<<'\n';
for(int i=0;i<50;i++){
a[i]="";
s2[i]=s;
}
for(int i=0;i<s.length();i++){
if(s[i]!='0'){
s1="";
for(int j=1;j<=i;j++) s1+='0';
int cnt=0;
s1+=10-s[i]+'0'+'0';
int j=i+1;
for(;j<s2[i].length();j++){
if(s2[i][j]!='9'){
s2[i][j]++;
for(int k=1;k<j-i;k++) s1+='0';
cnt=j-i;
break;
}
}
if(cnt>kk) continue;
// cout<<i<<'|';
while(cnt<kk){
// cout<<cnt<<'|';
int ggg=0;
for(int k=j+1;k<s2[i].length();k++){
if(s2[i][k]!='9'){
if((k-j+cnt)<=kk){
s1+=10-s2[i][j]+'0'+'0';
for(int g=1;g<k-j;g++) s1+='0';
cnt+=(k-j);
j=k;
ggg=1;
s2[i][k]++;
break;
}
}
}
if(ggg==0){
s1+='0';
j++;
}
}
// cout<<'\n';
// cout<<s1<<'\n';
if(cnt==kk){
ss="";
for(int k=s1.length()-1;k>=0;k--){
ss+=s1[k];
}
a[i]=ss;
}
}
}
// cout<<a[1]<<'|';
for(int i=0;i<50;i++){
// cout<<a[i]<<'|';
ss="";int ff=0;
for(int j=0;j<a[i].length();j++){
if(a[i][j]!='0') ff=1;
if(ff==1) ss+=a[i][j];
}
a[i]=ss;
if(a[i].length()!=0){
if(minn==-1){
minn=a[i].length();
}
else{
minn=min(minn,(int)a[i].length());
}
}
}
// cout<<minn<<'\n';
sort(a,a+50);
for(int i=0;i<50;i++){
int g=a[i].length();
if(g==minn){
cout<<a[i]<<'\n';return;
}
}
// cout<<minn<<'\n';
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(0),cout.tie(0);
int t;
cin>>t;
while(t--){
solve();
}
return 0;
}
// 4
// 12345678 0
// 12345678 5
// 12345678 18
// 990099 5
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3444kb
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: 3320kb
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 10999910000 9999910000 9999901000 9999900100 9999900010 9999900001 9000009999900001 99000009999900001 999000009999900001 99999999999999999900000000000000000 1000000000000000000
result:
wrong answer 11th lines differ - expected: '10000000001', found: '10999910000'