QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#504621#9107. Zayin and CountWorldFinalEscaped#AC ✓11ms3844kbC++141.7kb2024-08-04 14:09:322024-08-04 14:09:33

Judging History

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

  • [2024-08-04 14:09:33]
  • 评测
  • 测评结果:AC
  • 用时:11ms
  • 内存:3844kb
  • [2024-08-04 14:09:32]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long Big;
int T,x,pos1[11],pos2[11],ans[10005]; char s[1005];
vector<int> a,b;
int main(){
    for (cin>>T; T; T--){
        a.clear(),b.clear();
        for (int i=0; i<10; i++) pos1[i]=pos2[i]=0;
        for (int i=0; i<10; i++){
            scanf("%d",&x);
            if (x) a.push_back(i),pos1[i]=a.size()-1;
        }
        for (int i=0; i<10; i++){
            scanf("%d",&x);
            if (x) b.push_back(i),pos2[i]=b.size()-1;
        }
        scanf("%s",s+1); int n=strlen(s+1);
        Big pw=1,cnt=0;
        if (a[0]==0){
            for (int i=n; i>=1; i--){
                cnt+=pw*pos1[s[i]-'0'];
                pw*=a.size();
            }
        } else {
            for (int i=n; i>=1; i--){
                cnt+=pw*(pos1[s[i]-'0']+1);
                pw*=a.size();
            }
            cnt--;
        }
        if (!cnt){
            printf("%d\n",b[0]);
            continue;
        }
        
        if (b[0]==0){
            int len=0;
            while (cnt) ans[++len]=b[cnt%b.size()],cnt/=b.size();
            reverse(ans+1,ans+1+len);
            for (int i=1; i<=len; i++) putchar(ans[i]+'0');puts("");
        } else {
            cnt++; int k=0; Big P=1,sum=0;
            while (1){
                P*=b.size(); k++;
                if (P+sum>=cnt) break;
                sum+=P;
            }
            cnt-=sum+1;
            for (int i=1; i<=k; i++) ans[i]=b[cnt%b.size()],cnt/=b.size();
            reverse(ans+1,ans+1+k);
            for (int i=1; i<=k; i++) putchar(ans[i]+'0'); puts("");
        }
    }
}
/*
1
0 1 1 0 0 0 0 0 0 0
0 0 0 1 1 0 0 0 0 0
112
*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 11ms
memory: 3844kb

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