QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#134988#6300. Best Carry Player 2yzhangWA 1ms3660kbC++142.5kb2023-08-05 10:30:222023-08-05 10:30:24

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-08-05 10:30:24]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3660kb
  • [2023-08-05 10:30:22]
  • 提交

answer

//μ's forever
#include <bits/stdc++.h>
#define ll long long
//#define getchar nc
using namespace std;
inline char nc(){
    static char buf[100000],*p1=buf,*p2=buf;
    return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
inline ll read()
{
    register ll x=0,f=1;register char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9')x=(x<<3)+(x<<1)+ch-'0',ch=getchar();
    return x*f;
}
inline void write(register int x)
{
    if(!x)putchar('0');if(x<0)x=-x,putchar('-');
    static int sta[20];register int tot=0;
    while(x)sta[tot++]=x%10,x/=10;
    while(tot)putchar(sta[--tot]+48);
}
int T,k;
ll n;
int a[40],tot,f[40][40][2];
int mst[40];
int main()
{
    T=read();
    while(T--){
        n=read(),k=read();
        tot=0;
        memset(a,0,sizeof(a));
        while(n){
            ++tot;
            a[tot]=n%10;
            n/=10;
        }
        memset(f,0,sizeof(f));
        f[0][0][0]=1;
        for(int i=1;i<=tot+k;++i)
            for(int j=0;j<=k;++j){
                //case 0
                f[i][j][0]|=f[i-1][j][0];
                if(a[i]!=9) f[i][j][0]|=f[i-1][j][1];
                //case 1
                if(a[i]!=0) f[i][j][1]|=f[i-1][j-1][0];
                f[i][j][1]|=f[i-1][j-1][1];
            }
        bool fl=0;
        if(f[tot+k][k][0]==0&&f[tot+k][k][1]==0) puts("-1");
        else{
            memset(mst,0,sizeof(mst));
            int cur=k;
            for(int i=tot+k;i>=1;--i){
                int val=-1;
                if(a[i]==9){
                    if(mst[i]==0&&f[i-1][cur][0]) val=0;
                    else if(cur&&f[i-1][cur-1][1]) val=0,--cur,mst[i-1]=1;
                    else val=1,--cur;
                }else if(a[i]==0){
                    if(mst[i]==0&&f[i-1][cur][0]|f[i-1][cur][1]){
                        val=0;
                    }
                    else val=9,--cur,mst[i-1]=1;
                }else{
                    if(mst[i]==0&&(f[i-1][cur][0]|f[i-1][cur][1])){
                        val=0;
                        if(f[i-1][cur][0]==0) mst[i-1]=1;
                    }
                    else if(cur&&f[i-1][cur-1][1]) val=10-a[i]-1,--cur,mst[i-1]=1;
                    else val=10-a[i],--cur;
                }
                if(val!=0) fl=1;
                if(fl||i==1) printf("%d",val);
                // cerr<<val;
            }
            puts("");
        }
    }
    return 0;
}

詳細信息

Test #1:

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

input:

4
12345678 0
12345678 5
12345678 18
990099 5

output:

0
54322
999999999987654322
9910

result:

wrong answer 1st lines differ - expected: '1', found: '0'