/ SeriousOJ /

Record Detail

Time Exceeded


  
# Status Time Cost Memory Cost
#1 Accepted 28ms 31.016 MiB
#2 Time Exceeded ≥1602ms ≥33.691 MiB
#3 Time Exceeded ≥1601ms ≥36.27 MiB

Code

//```//    YF YUSUF
#define Free_open(File) freopen((File".in"),"r",stdin);freopen((File".out"),"w",stdout);
#define YF ios_base::sync_with_stdio(0);cout.setf(ios::fixed);
#define YUSUF cout.precision(0);cout.tie(0);cin.tie(0);
//#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <unordered_map>
#include <cmath>
#include <numeric>
#include <queue>
#include <stack>
#include <cassert>
#include <climits>
#include <string>
using namespace std;
#ifdef YF_CHECK
	bool Output=1;
//	#include "g/debug.h"
//  #include "g/bigint.h"
//	#include "g/text.h"
#else
	#pragma GCC optimize ("unroll-loops")
	#pragma GCC optimize ("inline")
	#pragma GCC optimize ("Ofast")
	#pragma GCC optimize ("O3")
	bool Output=0;
	#define deb(x...) 42 
#endif
using ll   = long long;
using ld   = long double;
using sll  = set <ll>;
using vll  = vector <ll>;
using mll  = map <ll,ll>;
using pll  = pair <ll,ll>;
using vvl  = vector <vll>;
using vpll = vector <pll>;
template<class T>T MIN(T&a,T b){a=min(a,b);return a;}
template<class T>T MAX(T&a,T b){a=max(a,b);return a;}
#define revers(a) reverse(all(a))
#define all(a) a.begin(),a.end()
#define sortt(a) sort(all(a))
#define sgr v+v+1,(tl+tr)/2+1,tr
#define sgl v+v,tl,(tl+tr)/2
#define pb push_back
#define ins insert
#define S second
#define F first
ll BP(ll a,ll b,ll mod=1e9+7){
	if(b==0)return 1;
	ll q=BP(a,b/2,mod);
	return ((q*q)%mod*(b%2?a:1ll))%mod;
}
ll dup(ll a,ll b){return (a+b-1)/b;}
ll f(ll x){return x*(x+1)/2;}
ll invf(ll x){return (-1+sqrt(1+8*x))/2;}
const ll  mod=998244353;
const ll  INF=1e18;
const ll  inf=1e9+7;
const ll  N  =1e6+7;
vll g[N];
vll used(N);
vll path;
ll n;
bool found = 0;
void dfs(ll v,ll d){
	if(found)return;
	used[v]=1;
	path.pb(v);
	if(d == n){
		found = 1;
		return;
	}
	for(auto to : g[v]){
		if(!used[to]){
			dfs(to,d+1);
			if(found)return;
		}
		
	}
	used[v]=0;
	path.pop_back();
}
void YF_MAIN(ll TEST){
	cin>>n;
	path.clear();
	found=0;
	for(int i=1;i<=n;i++){
		g[i].clear();
		used[i]=0;
	}
	for(int i=1;i<=n;i++){
		for(int j=i+2;j<=n;j++){
			if(__gcd(i,j)==1){
				g[i].pb(j);
				g[j].pb(i);
			}
		}
	}
	if(n<=4 || n==6){
		cout<<"-1";
		return;
	}
	for(int s=1;s<=n;s++){
		fill(all(used),0);
		path.clear();
		found=0;
		dfs(s,1);
		if(found){
			for(auto i : path)cout<<i<<" ";
			return;
		}
	}
	cout<<"-1";
}
bool TECT=1;
bool CASE=0;
bool OUTP=1;
bool LOUT=1;
const ll LN=2e1+7; ll lg[LN];
const ll SN=2e1+7; ll SM[SN];
const ll FN=2e1+7; 
ll FACT[FN],inv[FN],FMOD=1e9+7;
ll PER(ll n,ll k){return FACT[n] *inv[n-k]%FMOD;}
ll CNK(ll n,ll k){return PER(n,k)*inv[k  ]%FMOD;}
void BEFORE(){
	for(ll i=2;i<SN;i++){
		if(SM[i])continue;
		for(ll j=i;j<SN;j+=i)
			MAX(SM[j],i);
	}
	for(int i=2;i<LN;i++) lg[i]=lg[i/2]+1;
	FACT[0]=inv[0]=1;
	for(int i=1;i<FN;i++){
		FACT[i]=FACT[i-1]*i%FMOD;
		inv[i]=BP(FACT[i],FMOD-2,FMOD);
	}
}
signed main(){
	if(OUTP){YF YUSUF}
//	Free_open("TEST");
	// cout<<(LOUT && Output ? "\nYF_OUTPUT:\n\n" : "");
	int TEST=1;
	if(TECT)
		cin>>TEST;
	BEFORE();
	for(int T=1;T<=TEST;T++){
		if(CASE)
			cout<<"Case "<<T<<": ";
		YF_MAIN(T);
		cout<<(T==TEST ? "" : "\n");
	}
	return 0;
} 
//```

Information

Submit By
Type
Submission
Problem
P1203 D. Roy Loves Permutation
Contest
Brain Booster #10
Language
C++17 (G++ 13.2.0)
Submit At
2025-06-13 16:53:28
Judged At
2025-06-13 16:53:28
Judged By
Score
2
Total Time
≥1602ms
Peak Memory
≥36.27 MiB