QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#504641#9104. Zayin and ForestCheek_support#TL 0ms0kbC++202.6kb2024-08-04 14:24:322024-08-04 14:24:34

Judging History

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

  • [2024-08-04 14:24:34]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:0kb
  • [2024-08-04 14:24:32]
  • 提交

answer

#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--;
            }
        }
        Write(Tim);

        int anslen=1;
        if(b[0]){
            while(poww(tot2,anslen)-1<Tim)anslen++;
        }else{
            int sum=anslen;
            while(sum+poww(tot2,anslen+1)-1<Tim){
                anslen++;
                sum+=poww(tot2,anslen);
            }
        }
        cout<<anslen<<endl;
        rep(i,1,anslen){
            __int128 tmp=poww(tot2,anslen-i);
            int cnt=0;
            while(Tim-tmp>=0){
                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

*/

详细

Test #1:

score: 0
Time Limit Exceeded

input:

1000000000 20000
2 384578735 526547442
1 64211261 592970906
1 512065247 448267721
1 44993150 127180320
1 880319036 927623947
1 170536687 572121854
1 896600029 804033011
1 666246328 754201635
1 654066651 179982083
2 240989825 984888006
2 372004567 858916479
2 76127818 98606736
1 181794163 902842353
1...

output:

355
5
55829
113
7
9998889
,
1
2
4361
13

result: