QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#220842 | #6300. Best Carry Player 2 | smallzhuzi# | WA | 1ms | 7636kb | C++14 | 1.5kb | 2023-10-20 21:33:46 | 2023-10-20 21:33:46 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ld long double
#define pb push_back
#define endl "\n"
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
typedef pair<int,int> pii;
const int N=1000010,inf=LLONG_MAX,mod=998244353;
int t,n,m,a[N],b[N],vis[N],ans[N];
string yes="Yes",no="No";
void solve(){
string s;
cin>>s>>m;
for(int i=1;i<=40;i++)a[i]=0,b[i]=0,ans[i]=0;
n=s.size();
for(int i=1;i<=40;i++){
if(i>n){
a[40-i+1]=0;
} else a[40-i+1]=s[n-i]-'0';
}
if(m==0){
for(int i=40;i>=1;i--){
ans[i]=0;
if(a[i]!=9){
ans[i]=1;
break;
}
}
int jud=0;
for(int i=1;i<=40;i++){
if(ans[i]!=0)jud=1;
if(jud)cout<<ans[i];
}
cout<<endl;
return ;
}
int jud0=1,st;
for(int i=40;i>=1;i--){
if(a[i]==0&&jud0)continue;
if(a[i]!=0&&jud0)jud0=0,st=i;
b[i]=1;
for(int j=i-1;j>=1;j--){
if(a[j]==9)b[i]++;
else break;
}
}
// for(int i=40;i>=1;i--){
// cout<<b[i]<<endl;
// }
int len=0,id;
for(int i=st;i>=1;i--){
int now=i;
id=now;
len=0;
while(len<m){
// cout<<len<<endl;
len+=b[now];
now-=b[now];
// if(now<0)break;
}
if(len==m)break;
}
// cout<<id<<endl;
for(int i=id;i>=id-m+1;i--){
ans[i]=10-a[i];
a[i-1]++;
}
int jud=0;
for(int i=1;i<=40;i++){
if(ans[i]!=0)jud=1;
if(jud)cout<<ans[i];
}
cout<<endl;
}
signed main(){
ios::sync_with_stdio(0);
cin.tie(0);
t=1;
cin>>t;
while(t--){
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 7636kb
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: 7516kb
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 99991000000 9999910000 9999901000 9999900100 9999900010 9999900001 9000009999900001 99000009999900001 999000009999900001 99999999999999999900000000000000000 1000000000000000000
result:
wrong answer 11th lines differ - expected: '10000000001', found: '99991000000'