QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#504880#9107. Zayin and Counturayaha_yahaura#AC ✓27ms3764kbC++142.5kb2024-08-04 16:54:572024-08-04 16:54:58

Judging History

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

  • [2024-08-04 16:54:58]
  • 评测
  • 测评结果:AC
  • 用时:27ms
  • 内存:3764kb
  • [2024-08-04 16:54:57]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const __int128 X=1;
const __int128 INF=X<<64;
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-1);
        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(k>INF){
        while(1);
    }
    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: 100
Accepted
time: 27ms
memory: 3764kb

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
41990991999414091249949
101364364636933104003903
57558888789255872922852552
757222758857875785288225787822
761161760076076167101117776167
56666586555668686566656586856566686658
15611661611611111511116116661611616155
505885888775005550558080707878
3912911219633669993999199
...

result:

ok 10000 lines