QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#293085 | #4891. 树上的孤独 | zxzxzxq | 0 | 0ms | 0kb | C++17 | 1.9kb | 2023-12-28 21:33:42 | 2023-12-28 21:33:43 |
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]==0) 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];
//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;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Runtime Error
Test #1:
score: 0
Runtime Error
input:
20 2000 2000 8 15 8 13 14 8 14 7 12 14 12 1 9 13 9 4 5 9 5 10 2 5 2 19 6 19 6 16 11 7 11 20 18 2 18 17 3 6 1395 1783 1395 1735 1735 457 457 739 739 438 438 101 101 441 441 1879 1879 1238 1238 501 501 1732 1732 1910 1910 2000 2000 834 834 917 917 111 111 780 780 1966 1966 1604 1604 623 623 1748 1748 ...
output:
result:
Subtask #2:
score: 0
Runtime Error
Test #3:
score: 0
Runtime Error
input:
20 200000 500000 8 18 8 4 2 4 2 14 13 4 13 16 6 4 6 3 1 4 1 17 15 6 15 19 7 17 7 11 5 14 5 10 20 7 12 15 9 8 165302 77239 165302 198189 165302 180850 165302 192738 165302 173589 165302 194087 165302 191990 165302 167370 165302 101092 165302 92553 165302 163654 165302 122381 165302 152105 165302 1919...
output:
result:
Subtask #3:
score: 0
Runtime Error
Test #7:
score: 0
Runtime Error
input:
20 100000 100000 16 12 16 20 6 12 6 18 2 16 2 8 5 20 5 13 3 6 3 11 19 11 19 17 9 12 9 15 4 15 4 7 10 5 14 15 14 1 85812 94626 85812 91172 91172 93788 93788 96567 96567 75524 75524 23275 23275 98340 98340 81608 81608 91480 91480 75108 75108 56605 56605 93317 93317 41617 41617 77160 77160 727 727 7559...
output:
result:
Subtask #4:
score: 0
Runtime Error
Test #13:
score: 0
Runtime Error
input:
1 200000 500000 189127 137023 189127 199761 199761 160701 160701 130639 130639 190908 190908 176819 176819 193363 193363 188021 188021 182446 182446 186028 186028 198828 198828 190792 190792 155378 155378 189428 189428 177276 177276 146159 146159 175923 175923 188073 188073 182206 182206 131072 1310...
output:
result:
Subtask #5:
score: 0
Runtime Error
Test #15:
score: 0
Runtime Error
input:
20 200000 1000000 13 10 13 5 19 5 19 20 15 10 15 6 12 6 12 3 8 10 8 2 1 20 1 11 14 10 14 16 18 3 18 7 4 3 9 10 9 17 194055 154514 194055 148156 148156 115271 115271 198116 198116 179433 179433 171975 171975 196600 196600 167194 167194 185078 185078 191409 191409 163496 163496 178243 178243 154093 15...