Submission #710581

# Submission time Handle Problem Language Result Execution time Memory
710581 2023-03-15T11:41:36 Z Astrayt Permutation (APIO22_perm) C++17
100 / 100
8 ms 356 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
 
vector<int> construct_permutation(ll k){
    vector<int> d, ans;
    ll tmp = k;
    while(tmp){
        d.pb(tmp & 3ll);
        tmp >>= 2;
    }
    if(d.back() == 2) ans = {0};
    if(d.back() == 3) ans = {1, 0};
    d.pop_back();
    while(d.size()){
        int x = d.back(), n = ans.size(); d.pop_back();
        if(x == 0){
            ans.pb(n), ans.pb(n + 1);
        }else if(x == 1){
            ans.pb(n), ans.pb(n + 1), ans.pb(-1);
        }else if(x == 2){
            ans.pb(n), ans.pb(-1), ans.pb(n + 1);
        }else if(x == 3){
            bool flag = 0, flag2 = 0;
            for(auto x:ans){
                flag |= (x == 1);
                if(flag && x == 0) flag2 = 1;
            }
            if(flag2){
                ans.pb(n), ans.pb(n + 1);
                for(auto &x:ans) x *= 2;
                ans.pb(3);
            }else{
                ans.pb(n), ans.pb(-1), ans.pb(n + 1), ans.pb(-2);
            }
        }
        vector<int> ls = ans;
        sort(ls.begin(), ls.end());
        for(auto &x:ans) x = lower_bound(ls.begin(), ls.end(), x) - ls.begin();
    }
    return ans;
}
 
/*
int main(){
    int q; cin >> q;
    while(q--){
        int k; cin >> k;
        vector<int> v = construct_permutation(k);
        for(auto x:v) cout << x << ' ';
        cout << '\n';
    }
}
*/
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 300 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 300 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 3 ms 296 KB Output is correct
6 Correct 4 ms 340 KB Output is correct
7 Correct 5 ms 296 KB Output is correct
8 Correct 8 ms 296 KB Output is correct
9 Correct 3 ms 340 KB Output is correct
10 Correct 5 ms 340 KB Output is correct
11 Correct 6 ms 336 KB Output is correct
12 Correct 6 ms 340 KB Output is correct
13 Correct 7 ms 356 KB Output is correct