QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#293068 | #6300. Best Carry Player 2 | zxzxzxq# | RE | 0ms | 0kb | C++17 | 1.7kb | 2023-12-28 21:15:59 | 2023-12-28 21:16:01 |
answer
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int maxn=55;
int n,a[maxn],k;
int r[maxn];
int ans[maxn],sz[maxn];
void print()
{
while(ans[n]==0&&n>1) n--;
for(int i=n;i;i--)
{
cout<<ans[i];
}
cout<<'\n';
}
void solve()
{
int t;
n=0;
cin>>t;
while(t)
{
a[++n]=t%10;
t/=10;
}
// reverse(a+1,a+n+1);
memset(sz,0,sizeof(sz));
memset(ans,0,sizeof(ans));
memset(r,0,sizeof(r));
cin>>k;
if(k==0)
{
int flag=0;
for(int i=1;i<=n;i++)
{
if(a[i]<9)
{
flag=1,ans[i]=1;
print();
return ;
}
}
ans[++n]=1;
print();
return ;
}
int looker=1;
while(a[looker]==0) looker++;
int ttarget=0;
if(n-looker+1<k) ttarget=k-(n-looker+1),k=n-looker+1;
for(int i=n;i;i--)
{
r[i]=i;
if(a[i+1]==9) r[i]=r[i+1],sz[r[i]]++;
}
int target=looker+k-1;
int backlooker=looker;
int nowcnt=0;
looker+=r[target]-target;
target=r[target];
int flooker=looker;
while(a[flooker]!=9) flooker++;
int lensize=flooker-looker;
if(lensize)
{
ans[backlooker]=10-a[backlooker];
for(int i=backlooker+lensize-1;i>backlooker;i--) ans[i]=9-a[i];
}
ans[flooker]=10-a[flooker];
for(int i=target;i>flooker;i--) ans[i]=9-a[i];
while(ttarget)
{
ans[++n]=9;
ttarget--;
}
print();
}
signed main()
{
ios::sync_with_stdio(false);
int T;
cin>>T;
while(T--)
{
solve();
}
return 0;
}
詳細信息
Test #1:
score: 0
Runtime Error
input:
4 12345678 0 12345678 5 12345678 18 990099 5
output:
1