QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#674277#9107. Zayin and Countucup-team5071#AC ✓14ms3496kbC++201.5kb2024-10-25 14:54:512024-10-25 14:54:51

Judging History

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

  • [2024-10-25 14:54:51]
  • 评测
  • 测评结果:AC
  • 用时:14ms
  • 内存:3496kb
  • [2024-10-25 14:54:51]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
typedef __int128 ll;
string solve()
{
    vector<int>a,b;
    vector<int>ida(10),idb(10);
    for(int i=0,j=0;i<10;i++){
        int x;cin>>x;
        if(x)a.push_back(i),ida[i]=j++;
    }
    for(int i=0,j=0;i<10;i++){
        int x;cin>>x;
        if(x)b.push_back(i),idb[i]=j++;
    }
    string s;cin>>s;
    ll now=0;
    if(a[0]==0){
        for(auto it:s)now=now*((ll)a.size())+ida[it-'0'];
    }
    else{
        ll p=a.size();
        for(int i=1;i<s.size();i++){
            now+=p;
            p*=a.size();
        }
        p=1;
        for(int i=s.size()-1;i>=0;i--){
            now+=(ida[s[i]-'0'])*p;
            p*=a.size();
        }
    }
    string ans;
    if(b[0]==0){
        do{
            ans.push_back(b[now%((ll)b.size())]+'0');
            now/=(ll)b.size();
        }while(now>0);
        reverse(ans.begin(),ans.end());
    }
    else{
        ll tot=0,p=b.size();
        int len=1;
        for(;;){
            if(tot+p<now){
                tot+=p;
                p*=b.size();
                len++;
            }
            else break;
        }
        p/=b.size();
        now-=tot;
        ans.resize(len);
        for(int i=0;i<len;i++){
            ans[i]='0'+b[(now%((ll)b.size()))];
            now/=b.size();
        }
        reverse(ans.begin(),ans.end());
    }
    return ans;
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int T;cin>>T;while(T--)cout<<solve()<<"\n";
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 14ms
memory: 3496kb

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