QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#485378#9107. Zayin and Countpropane#AC ✓28ms3652kbC++202.7kb2024-07-20 17:20:102024-07-20 17:20:12

Judging History

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

  • [2024-07-20 17:20:12]
  • 评测
  • 测评结果:AC
  • 用时:28ms
  • 内存:3652kb
  • [2024-07-20 17:20:10]
  • 提交

answer

#include<iostream>
#include<cstring>
#include<vector>
#include<climits>
#include<algorithm>
using namespace std;
using LL = long long;
using i128 = __int128_t;
const i128 INF = 1e22;

int main(){

#ifdef LOCAL
    freopen("data.in", "r", stdin);
    freopen("data.out", "w", stdout);
#endif

    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(0);
    int T;
    cin >> T;
    while(T--){
        vector<int> p1, p2;
        vector<int> id1(10), id2(10);
        for(int i = 0; i < 10; i++){
            int x;
            cin >> x;
            if (x){
                id1[i] = p1.size();
                p1.push_back(i);
            }
        }
        for(int i = 0; i < 10; i++){
            int x;
            cin >> x;
            if (x){
                id2[i] = p2.size();
                p2.push_back(i);
            }
        }
        string s;
        cin >> s;
        vector<i128> pows(s.size() + 1);
        pows[0] = 1;
        for(int i = 1; i <= s.size(); i++){
            pows[i] = pows[i - 1] * p1.size();
        }
        i128 v = 0;
        for(int i = 1; i < s.size(); i++){
            if (p1[0] == 0){
                v += pows[i - 1] * (p1.size() - 1);
                if (i == 1) v += 1;
            }
            else{
                v += pows[i];
            }
        }
        for(int i = 0; i < s.size(); i++){
            int x = s[i] - '0';
            for(int j = 0; j < p1.size(); j++){
                if (p1[j] >= x) continue;
                if (p1[j] == 0 and i == 0) continue;
                v += pows[s.size() - 1 - i];
            }
        }

        v += 1;
        pows.resize(70);
        pows[0] = 1;
        for(int i = 1; i < 70; i++){
            pows[i] = pows[i - 1] * p2.size();
            if (pows[i] > INF) pows[i] = INF;
        }
        for(int len = 1; ; len++){
            i128 cur = 0;
            if (p2[0] == 0){
                cur = pows[len - 1] * (p2.size() - 1);
                if (len == 1) cur += 1;
            }
            else{
                cur = pows[len];
            }
            if (cur >= v){
                for(int i = 1; i <= len; i++){
                    for(int j = 0; j < p2.size(); j++){
                        if (p2[j] == 0 and i == 1) continue;
                        i128 val = pows[len - i];
                        if (v > val){
                            v -= val;
                        }
                        else{
                            cout << p2[j];
                            break;
                        }
                    }
                }
                break;
            }
            v -= cur;
        }
        cout << '\n';
    }

}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 28ms
memory: 3652kb

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