QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#504825#9107. Zayin and Counturayaha_yahaura#RE 0ms0kbC++142.4kb2024-08-04 16:29:262024-08-04 16:29:28

Judging History

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

  • [2024-08-04 16:29:28]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2024-08-04 16:29:26]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
int T,n,m,la,lb,a[11],b[11],ra[11],rb[11],d[77];
char s[77];
__int128 k,ca[77],cb[77],sa[77],sb[77];
void write(__int128 x){
    char buf[33];
    int len=0;
    do{
        int t=x%10;
        buf[++len]=t^48;
        x/=10;
    }while(x);
    for(int i=len;i;--i)
        fprintf(stderr,"%c",buf[i]);
    fprintf(stderr,"\n");
}
void solve(){
    int fa=0,cna=0,fb=0,cnb=0;
    for(int i=0;i<10;++i){
        scanf("%d",a+i);
        if(a[i]){
            ++cna;
            ra[cna]=i;
            if(!i)
                fa=1;
        }
        if(i)
            a[i]+=a[i-1];
    }
    for(int i=0;i<10;++i){
        scanf("%d",b+i);
        if(b[i]){
            ++cnb;
            rb[cnb]=i;
            if(!i)
                fb=1;
        }
        if(i)
            b[i]+=b[i-1];
    }
    scanf("%s",s+1);
    n=strlen(s+1);
    for(int i=1;i<=n;++i)
        d[i]=s[i]^48;
    ca[1]=cna;
    cb[1]=cnb;
    sa[1]=ca[1];
    sb[1]=cb[1];
    for(int i=2;i<=n;++i){
        if(!fa)
            ca[i]=ca[i-1]*cna;
        else
            ca[i]=sa[i-1]*cna;
        sa[i]=sa[i-1]+ca[i];
    }
    if(!fa){
        k=(a[d[1]]-1)*ca[n-1]+sa[n-1]+a[d[n]];
        for(int i=2;i<n;++i)
            k+=(a[d[i]]-1)*ca[n-i];
    }
    else{
        k=(a[d[1]]-1)*sa[n-1]+a[d[n]];
        for(int i=2;i<n;++i)
            k+=(a[d[i]]-1)*sa[n-i];
    }
    if(sb[1]>k)
        m=1;
    else{
        for(int i=2;i<=67;++i){
            if(!fb)
                cb[i]=cb[i-1]*cnb;
            else
                cb[i]=sb[i-1]*(cnb-1);
            sb[i]=sb[i-1]+cb[i];
            if(sb[i]>k){
                m=i;
                break;
            }
        }
    }
    if(m>1){
        if(!fb){
            d[1]=rb[(k-sb[m-1]-1)/cb[m-1]+1];
            k-=(b[d[1]]-1)*cb[m-1]+sb[m-1];
            for(int i=2;i<m;++i){
                d[i]=rb[(k-1)/cb[m-i]+1];
                k-=(b[d[i]]-1)*cb[m-i];
            }
        }
        else{
            d[1]=rb[(k-1)/sb[m-1]+1];
            k-=(b[d[1]]-1)*sb[m-1];
            for(int i=2;i<m;++i){
                d[i]=rb[(k-1)/sb[m-i]+1];
                k-=(b[d[i]]-1)*sb[m-i];
            }
        }
    }
    d[m]=rb[k];
    for(int i=1;i<=m;++i)
        printf("%d",d[i]);
    puts("");
}
int main(){
    scanf("%d",&T);
    while(T--)
        solve();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Runtime Error

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:


result: