Submission #928613

# Submission time Handle Problem Language Result Execution time Memory
928613 2024-02-16T19:09:31 Z MilosMilutinovic Permutation (APIO22_perm) C++17
100 / 100
3 ms 348 KB
#include "perm.h"
#include<bits/stdc++.h>
 
#define pb push_back
#define fi first
#define se second
#define mp make_pair
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef long double ld;
 
template <typename T> bool chkmin(T &x,T y){return x>y?x=y,1:0;}
template <typename T> bool chkmax(T &x,T y){return x<y?x=y,1:0;}
 
ll readint(){
	ll x=0,f=1; char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}

vector<int> primes={2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89};

vector<int> construct_permutation(ll k){
	if(k==1) return {};
	if(k==2) return {0};
	for(int i:primes){
		if(i<k&&k%i==0){
			vector<int> a=construct_permutation(k/i);
			vector<int> b=construct_permutation(i);
			for(int i=0;i<(int)b.size();i++) b[i]+=a.size();
			vector<int> ret;
			for(int i:a) ret.pb(i);
			for(int i:b) ret.pb(i);
			return ret;
		}
	}
	vector<int> a=construct_permutation(k/2);
	a.pb(a.size());
	vector<int> ret;
	if(k%2==1) ret.pb(a.size());
	for(int i:a) ret.pb(i);
	return ret;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 3 ms 348 KB Output is correct
8 Correct 2 ms 348 KB Output is correct
9 Correct 2 ms 348 KB Output is correct
10 Correct 2 ms 348 KB Output is correct
11 Correct 2 ms 348 KB Output is correct
12 Correct 2 ms 348 KB Output is correct
13 Correct 2 ms 348 KB Output is correct