QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#575422#9107. Zayin and Countleafmaple#AC ✓23ms3796kbC++202.3kb2024-09-19 14:06:292024-09-19 14:06:30

Judging History

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

  • [2024-09-19 14:06:30]
  • 评测
  • 测评结果:AC
  • 用时:23ms
  • 内存:3796kb
  • [2024-09-19 14:06:29]
  • 提交

answer

#include <bits/stdc++.h>
#define endl '\n'
using namespace std;
using ll = long long;
const int N=1e6+5;
#define int unsigned long long
int cal(vector<int> vec, string s){
    int cnt = 0;
    int tot = 0;
    map<int,int>mp;
    if(vec[0] == 1){    
        for(int i=0; i<10; i++) if(vec[i]) {
            cnt++;
            mp[i] = tot++;
        }
        for(auto &c: s){
            int x = c-'0';
            c = mp[x] + '0';
        }
        int ans = 0;
        for(int i=0; i<s.size(); i++){
            ans = ans * cnt + s[i]-'0';
        }
        return ans+1;
    }else {
        for(int i=0; i<10; i++) if(vec[i]) {
            cnt++;
            mp[i] = ++tot;
        }
        for(auto &c: s){
            int x = c-'0';
            c = mp[x] + '0';
        }
        int ans = 0;
        for(int i=0; i<s.size(); i++){
            ans = ans * cnt + s[i]-'0';
        }
        return ans;
    }
}

/*
    (x,y,z) -> (sx,sy,sz)
    (x,y,z) + 
    (sx+1,y,z) (x,sy+1,z) (x,y,sz+1)-
    (sx+1,sy+1,z)+ (sx+1,y,sz+1)+ (x,sy+1,sz+1) +
    (sx+1,sy+1,sz+1) -
*/
void fk(vector<int>vec, int k){
    map<int,int>mp;
   

    int cnt = 0, tot = 0;
    if(vec[0] == 1){
        k-=1;
        for(int i=0; i<10; i++) if(vec[i]) {
            cnt++;
            mp[tot++] = i;
        }
        string ans;
        while(k){
            ans += k%cnt + '0';
            k /= cnt;
        }
        for(auto &c: ans){
            c = mp[c-'0'] + '0';
        }
        reverse(ans.begin(), ans.end());
        cout << ans << endl;
        return ;
    }
    for(int i=0; i<10; i++) if(vec[i]) {
        cnt++;
        mp[tot++] = i;
    }
    k--;
    int sum = 0, p = 1, m = 1;
    while (k >= sum + p * cnt){
        p *= cnt;
        sum += p;
        m++;
    }
    k -= sum;
    string ans;
    while (m--)
    {
        ans += '0' + mp[k % cnt]; 
        k /= cnt;
    }
    reverse(ans.begin(), ans.end());
    cout << ans << endl;   




}

void solve(){
    vector<int>a(15), b(15);
    for(int i=0; i<10; i++) cin >> a[i];
    for(int i=0; i<10; i++) cin >> b[i];
    string x; cin >> x;
    int k = cal(a, x);
    // cout << k << endl;
    fk(b, k);

}

signed main(){
    cin.tie(0)->sync_with_stdio(0);
    int T; T=1;
    cin >> T;
    while(T--) solve();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 23ms
memory: 3796kb

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