/ SeriousOJ /

Record Detail

Time Exceeded


  
# Status Time Cost Memory Cost
#1 Accepted 2ms 376.0 KiB
#2 Time Exceeded ≥1530ms ≥568.0 KiB
#3 Wrong Answer 1345ms 568.0 KiB

Code

#include<bits/stdc++.h>
using namespace std;

/*#ifndef ONLINE_JUDGE
#include "DEBUG.h"
#define bug(...)           __f (#__VA_ARGS__, __VA_ARGS__)
#endif*/

#define first_in_out       ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll                 long long int
#define double             long double
#define print(a)           for(auto x : a) cout << x << " ";
#define printpair(a)       for(auto x : a) cout << x.first << " " << x.second<<"\n";

mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

void solve()
{
	int n;
	cin >> n;


	if (n <= 4)
	{
		cout << "-1" << "\n";
		return;
	}

	vector<int>v(n);

	for (int i = 0; i < n; i++)
		v[i] = i + 1;


	int cnt = 1e5;

	while (cnt--) {

		bool f = 0;
		for (int i = 0; i < n - 1; i++)
		{

			if (abs(v[i + 1] - v[i]) > 1 and __gcd(v[i + 1], v[i]) == 1)
				;
			else
			{
				f = 1;
				break;
			}
		}

		if (!f)
		{
			print(v);
			cout << "\n";
			return;
		}
		shuffle(v.begin(), v.end(), rnd);
	}

	cout << -1 << "\n";
}


int main()
{
	first_in_out

	int t = 1;
	cin >> t;

	while (t--)
		solve();

}

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:03:12
Judged At
2025-06-13 16:03:12
Judged By
Score
2
Total Time
≥1530ms
Peak Memory
≥568.0 KiB