Submission #1202881

#TimeUsernameProblemLanguageResultExecution timeMemory
1202881browntoadPermutation (APIO22_perm)C++20
0 / 100
0 ms324 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++;
}

std::vector<int> construct_permutation(long long k){
	int 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)){
		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;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...