Submission #704741

#TimeUsernameProblemLanguageResultExecution timeMemory
704741beaconmcPermutation (APIO22_perm)C++17
100 / 100
2 ms376 KiB
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include "perm.h"


typedef long long ll;
#define FOR(i,x,y) for(ll i=x; i<y; i++)

using namespace std;


vector<int> perm(ll k, ll shi){


	if (k==2){
		return {(int)shi};
	}
	ll imp = k;
	vector<ll> ops;
	deque<ll> sus;

	while (k>1){
		bool flag = false;
		FOR(i,2,min((ll)10, (ll)k)){

			if (k%i==0){
				ops.push_back(i);
				k /= i;
				flag = true;
				break;
			}
		}
		if (flag) continue;
		ops.push_back(1);
		k -= 1;


	}
	ll cur = shi;
	reverse(ops.begin(), ops.end());

	for (auto&i : ops){
		if (i==1) sus.push_front(cur++);

		else{
			ll temp = 0;
			for (auto&j : perm(i, cur)){
				temp++;
				sus.push_back(j);
			}
			cur += temp;
		}
	}
	vector<int> ans;
	for (auto&i : sus) ans.push_back(i);
	return ans;
}
vector<int> construct_permutation(long long k){
	return perm(k, 0);
}



Compilation message (stderr)

perm.cpp: In function 'std::vector<int> perm(ll, ll)':
perm.cpp:19:5: warning: unused variable 'imp' [-Wunused-variable]
   19 |  ll imp = k;
      |     ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...