Submission #1202924

#TimeUsernameProblemLanguageResultExecution timeMemory
1202924browntoadPermutation (APIO22_perm)C++20
0 / 100
0 ms320 KiB
#include "perm.h"
#include <bits/stdc++.h>
using namespace std;
#define ll long long
// #define int ll
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define REP1(i, n) FOR(i, 1, n+1)
#define RREP(i, n) for (int i = (n)-1; i >= 0; i--)
#define pii pair<int, int>
#define f first
#define s second
#define pb push_back
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) (int)((x).size())

namespace{
    const ll maxn  = 1e5+5;
    const ll mod = 1e9+7;
    const ll inf = (1ll<<60);

	vector<int> ans, pos;
	int m;
}

void add_max(){
	ans.pb(m); pos.pb(m);
	m++;
}
void add_min(){
	pos.pb(0);
	REP(i, m){
		ans[i]++;
		pos[ans[i]] = i;
	}
	pos[0] = m;
	ans.pb(0);
	m++;
}
/*
int calcc(vector<int> vc){
    int n = SZ(vc);
    int ans = 0;
    REP(b, (1<<n)){
        bool gg = 0;

        int plee = -1;
        REP(j, n){
            if ((b>>j)&1){
                if (plee >= vc[j]){
                    gg = 1;
                    break;
                }
                plee = vc[j];
            }
        }
        ans += (!gg);
    }
    return ans;
}*/
std::vector<int> construct_permutation(long long k){
  assert(k >= 2);
  assert(k <= 90);
	ll tk = k;
	m = 0;
	ans.clear(); pos.clear();
	vector<int> rep;
	while(tk > 0){
		int tmp = tk%4;
		rep.pb(tmp);
		tk /= 4;
	}
	reverse(ALL(rep));

	REP(i, SZ(rep)){
	    cout<<rep[i]<<endl;
		if (i == 0){
			if (rep[i] == 1) continue;
			if (rep[i] == 2){
				m++;
				ans.pb(0);
				pos.pb(0);
			}
			else{
				m += 2;
				ans.pb(1); ans.pb(0);
				pos.pb(1); pos.pb(0);
			}
			continue;
		}

		if (rep[i] == 0){
			add_max(); add_max();
		}
		else if (rep[i] == 1){
			add_max(); add_max();
			add_min();
		}
		else if (rep[i] == 2){
			add_max(); add_min(); add_max();
		}
		else{
			if (m >= 2 && pos[1] < pos[0]){
				add_max(); add_max();
				// add small + 1.5
				pos.pb(0);
				REP(i, m){
					if (ans[i] >= 2){
						ans[i]++;
						pos[ans[i]] = i;
					}
				}
				ans.pb(2);
				pos[2] = m;
				m++;
			}
			else{
				add_max(); add_min(); add_max(); add_min();
			}
		}
	}
	return ans;
}
/*
signed main(){
    vector<int> dick = construct_permutation(19);
    for (auto x:dick) cout<<x<<endl;
    cout<<calcc(dick)<<endl;
}
*/
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...