QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#293065#6300. Best Carry Player 2zxzxzxq#WA 1ms3344kbC++172.0kb2023-12-28 21:13:042023-12-28 21:13:04

Judging History

你现在查看的是最新测评结果

  • [2023-12-28 21:13:04]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3344kb
  • [2023-12-28 21:13:04]
  • 提交

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]; nowcnt++;
    for(int i=looker+1;i<=n&&r[i]!=r[target];i++) ans[i]=9-a[i],nowcnt++;
    // 从左边切
    ans[r[target]-(k-nowcnt)+1]=10-a[r[target]-(k-nowcnt)+1]; 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

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 3344kb

input:

4
12345678 0
12345678 5
12345678 18
990099 5

output:

1
64322
999999999997654322
10901

result:

wrong answer 2nd lines differ - expected: '54322', found: '64322'