QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#504695#9107. Zayin and CountCheek_support#WA 21ms3724kbC++202.7kb2024-08-04 14:55:382024-08-04 14:55:38

Judging History

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

  • [2024-08-04 14:55:38]
  • 评测
  • 测评结果:WA
  • 用时:21ms
  • 内存:3724kb
  • [2024-08-04 14:55:38]
  • 提交

answer

#pragma GCC optimize("Ofast")
#pragma GCC optimize("inline")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#define rep(i,j,k) for(int i=j;i<=k;i++)
#define INT __int128
using namespace std;
int read(){
    char ch=getchar();int x=0,f=1;
    for(;ch<'0'||ch>'9';ch=getchar())if(ch=='-')f=-1;
    for(;ch>='0'&&ch<='9';ch=getchar())x=x*10+ch-'0';
    return f*x;
}
template<typename T> void write(T x){
    if(x>9)write(x/10);
    putchar(x%10+'0');
}
template<typename T> void Write(T x){
    write(x);putchar('\n');
}
int a[20],b[20];
int rka[20],rkb[20];
int tpa[20],tpb[20];
char Num[110];
char Ans[110];
INT poww(INT n,INT m){
    INT ret=1;INT temp=n;INT tmp=m;
    while(tmp){
        if(tmp&1)ret*=temp;
        temp*=temp;
        tmp>>=1;
    }
    return ret;
}
int main(){
    int T=read();
    while(T--){
        int tot1=0;
        rep(i,0,9){
            a[i]=read();
            tot1+=(a[i]==1);
            if(a[i]){
                rka[i]=tot1;
                tpa[tot1]=i;
            }
        }

        int tot2=0;
        rep(i,0,9){
            b[i]=read();
            tot2+=(b[i]==1);
            if(b[i]){
                rkb[i]=tot2;
                tpb[tot2]=i;
            }
        }

        scanf("%s",Num+1);
        int len=strlen(Num+1);

        __int128 Tim=0;
        rep(i,1,len){
            int x=Num[i]-'0';
            int rk=rka[x];
            if(a[0]){
                Tim+=poww(tot1,len-i)*(rk-1);
            }else{
                Tim+=poww(tot1,len-i)*rk;
                if(i==len)Tim--;
            }
        }

        int anslen=1;
        __int128 sum=tot2;
        if(b[0]){
            while(poww(tot2,anslen)-1<Tim)anslen++;
        }else{
            while(sum-1<Tim){
                anslen++;
                sum+=poww(tot2,anslen);
            }
        }
        sum=0;
        rep(i,1,anslen-1)sum+=poww(tot2,i);

        rep(i,1,anslen){
            if(i!=anslen)sum-=poww(tot2,anslen-i);
            __int128 tmp=poww(tot2,anslen-i);
            int cnt=0;
            while(Tim-tmp>=sum){
                Tim-=tmp;
                cnt++;
            } 
            if(b[0]){
                int x=tpb[cnt+1];
                Ans[i]=x+'0';
            }else{
                if(i==anslen)cnt++;
                int x=tpb[cnt];
                Ans[i]=x+'0';
            }
            
        }

        rep(i,1,anslen)putchar(Ans[i]);
        putchar('\n');
    }
    return 0;
}
/*
4
1 0 1 0 0 0 0 0 0 0
1 1 0 0 0 0 0 0 0 0
20
0 1 1 0 0 0 0 0 0 0
1 0 0 1 0 0 0 0 0 0
2
0 1 1 0 0 0 0 0 0 0
0 1 0 1 0 0 0 0 0 0
12
0 0 1 1 0 0 0 0 0 0
0 1 0 1 0 1 0 0 0 0
32223

*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 21ms
memory: 3724kb

input:

10000
1 0 0 0 1 1 0 0 0 1
0 0 1 0 1 1 1 1 0 0
950595954440050004054505054050
1 0 0 0 1 1 1 1 0 0
1 1 1 0 1 0 0 0 1 1
45467007076660767550460064
1 1 1 1 0 0 0 1 0 0
1 1 0 1 1 0 1 0 0 1
23373171320213300170200722
0 0 0 0 1 1 1 0 1 0
0 0 1 0 0 1 0 1 1 1
558565664666565565558468668484
1 1 0 0 1 0 1 0 1 ...

output:

52755244567262766742575722
41980991999412091249949
001364364636931003903603
57558888789255872922852552
757222758857875785288225787822
761161717971976166991117776167
56666586555668686566656586856566686658
15611661611611111511116116661611616155
095885888759889999557979597878
3912911219633669993999199
...

result:

wrong answer 2nd lines differ - expected: '41990991999414091249949', found: '41980991999412091249949'