QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#293040 | #6300. Best Carry Player 2 | zxzxzxq# | RE | 1ms | 3448kb | C++17 | 1.7kb | 2023-12-28 20:40:07 | 2023-12-28 20:40:07 |
Judging History
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--;
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 ;
}
}
a[++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 nowcnt=0;
looker+=r[target]-target;
target=r[target];
ans[looker]=10-a[looker];
for(int i=target;i>looker;i--) ans[i]=9-a[i];
//ans[looker]=10-a[looker];
//for(int i=looker+1;i<=n&&r[i]!=r[target];i++) ans[i]=9-a[i],nowcnt++;
//从左边切
//for(int i=r[target]-(k-nowcnt)+1;i<=r[target];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: 100
Accepted
time: 1ms
memory: 3448kb
input:
4 12345678 0 12345678 5 12345678 18 990099 5
output:
1 54322 999999999987654322 9910
result:
ok 4 lines
Test #2:
score: -100
Runtime Error
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 1398953987499201398953987499041398953987500161398953987427520940757153587841398953...