QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#504599#9107. Zayin and CountIllusionaryDominance#AC ✓20ms3920kbC++141.4kb2024-08-04 14:00:472024-08-04 14:00:48

Judging History

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

  • [2024-08-04 14:00:48]
  • 评测
  • 测评结果:AC
  • 用时:20ms
  • 内存:3920kb
  • [2024-08-04 14:00:47]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
int A[10], B[10], rnkA[20], idsB[20];
int main(){
    ios::sync_with_stdio(0); cin.tie(0), cout.tie(0);
    int T; cin >> T;
    while(T --){
        for (int i = 0; i <= 9; ++ i) cin >> A[i];
        int totA = 0;
        for (int i = 0; i <= 9; ++ i) if(A[i]) rnkA[i] = ++ totA;
        for (int i = 0; i <= 9; ++ i) cin >> B[i];
        int totB = 0;
        for (int i = 0; i <= 9; ++ i) if(B[i]) idsB[++ totB] = i;
        __int128 x = 0;
        char s[100000];
        cin >> s + 1; int n = strlen(s + 1);
        for (int i = 1; i <= n; ++ i) x = x * totA + rnkA[s[i] - '0'];
        __int128 pw = totA;
        for (int i = 2; i <= n; ++ i){
            x -= A[0] * pw;
            pw *= totA;
        }
        if(x <= totB) cout << idsB[x] << "\n";
        else{
            __int128 now = totB, pw = totB, len = 1;
            while(now + pw * (totB - B[0]) < x){
                now += pw * (totB - B[0]);
                ++ len;
                pw = pw * totB;
            }
            int fir = 1 + B[0];
            while(now + pw < x) ++ fir, now += pw;
            x -= now + 1;
            cout << idsB[fir];
            for (int i = 1; i <= len; ++ i){
                pw /= totB;
                cout << idsB[x / pw + 1];
                x %= pw;
            }
            cout << "\n";
        }
        
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 20ms
memory: 3920kb

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