QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#293191#6300. Best Carry Player 2zxzxzxqWA 68ms3680kbC++172.0kb2023-12-28 23:06:222023-12-28 23:06:22

Judging History

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

  • [2023-12-28 23:06:22]
  • 评测
  • 测评结果:WA
  • 用时:68ms
  • 内存:3680kb
  • [2023-12-28 23:06:22]
  • 提交

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;
    memset(a,0,sizeof(a));
    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)
    {
        if(r[backlooker]!=backlooker) backlooker=r[backlooker]-lensize+1;
        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;
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 3616kb

input:

4
12345678 0
12345678 5
12345678 18
990099 5

output:

1
54322
999999999987654322
9910

result:

ok 4 lines

Test #2:

score: 0
Accepted
time: 0ms
memory: 3624kb

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
10000000001
9999910000
9999901000
9999900100
9999900010
9999900001
9000009999900001
99000009999900001
999000009999900001
99999999999999999900000000000000000
1000000000000000000

result:

ok 21 lines

Test #3:

score: -100
Wrong Answer
time: 68ms
memory: 3680kb

input:

100000
119111011091190000 10
1911011191011999 16
110099199000119 0
19009911191091011 13
199090909919000900 17
19009010011919110 5
90910190019900091 18
10911100000101111 1
110090011101119990 4
100909999119090000 12
90901119109011100 2
111010119991090101 4
900991019109199009 5
100919919990991119 8
911...

output:

88988908810000
8088988808988001
10
88808908989
9800909090080999100
80890
909089809980099909
9
80010
9090000880910000
8900
9909
991
9008900
8880880090
8080090801
8009900808909899
80880898981
909
8800909
99988889901
89908888089
980908890980099000
100
9889801
81
908890008099900891
880990801
9998099
890...

result:

wrong answer 882nd lines differ - expected: '98988890900090', found: '98988890900081'