QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#220851 | #6300. Best Carry Player 2 | kokosuki# | WA | 0ms | 3680kb | C++14 | 1.6kb | 2023-10-20 21:41:49 | 2023-10-20 21:41:51 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N =1e5+10;
int a[N],p[N];
int ans[N];
char x[N];
int k;
void ch(int l,int r)
{
for(int i=l;i<=r;i++)
{
ans[i]=9-a[i];
k--;
}
ans[r]++;
if(l>1&&ans[l-1]>0) ans[l-1]--;
}
void sl()
{
cin>> x+1;
cin>>k;
int n=strlen(x+1);
for(int i=1;i<=n;i++)
{
a[i]=x[i]-'0';
// cout<<a[i]<<' ';
}
if(k==0)
{
int flag=1;
for(int i=n;i>=1;i--)
{
if(a[i]!=9)
{
cout<<p[n-i]<<endl;
flag=0;
break;
}
}
if(flag) cout<<p[n]<<endl;
return ;
}
int r;
for(r=n;r;r--)
{
if(a[r]!=0) break;
}
int rr=r;
// cout<<r<<endl;
int l=r-k+1;
int op=1;
// cout<<l<<endl;
if(l<1)
{
ch(1,r);
while(k--)
{
cout<<9;
l++;
}
for(int i=1;i<=r;i++)
{
// if(op==1&&ans[i]==0) continue;
// if(ans[i]!=0) op=0;
cout<<ans[i];
}
}
else if(a[l-1]!=9||l==1)
{
ch(l,r);
for(int i=l;i<=r;i++)
{
if(op==1&&ans[i]==0) continue;
if(ans[i]!=0) op=0;
cout<<ans[i];
}
}
else
{
while(l>1&&a[l-1]==9) l--;
r=l+k-1;
rr=r;
int cnt=0;
while(r>l&&a[r]==0) r--,cnt++;
while(cnt--)
{
cout<<9;
op=1;
}
ch(l,r);
for(int i=l;i<=r;i++)
{
if(op==1&&ans[i]==0) continue;
if(ans[i]!=0) op=0;
cout<<ans[i];
}
}
// cout<<endl<<l<<' '<<r<<' '<<rr<<endl;
for(int i=rr+1;i<=n;i++)
{
cout<<0;
}
cout<<endl;
}
int main()
{
p[0]=1;
for(int i=1;i<=20;i++)
{
p[i]=p[i-1]*10;
}
int t;
cin>>t;
while(t--)
{
sl();
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
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: 3620kb
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 99999100000 9999910000 9999901000 9999900100 9999900010 9999900001 9000009999900001 99000009999900001 999000009999900001 99999999999999999900000000000000000 -1486618624
result:
wrong answer 11th lines differ - expected: '10000000001', found: '99999100000'