QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#293068#6300. Best Carry Player 2zxzxzxq#RE 0ms0kbC++171.7kb2023-12-28 21:15:592023-12-28 21:16:01

Judging History

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

  • [2023-12-28 21:16:01]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2023-12-28 21:15:59]
  • 提交

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

result: