Wrong Answer
Code
#include <bits/stdc++.h>
using namespace std;
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
int T;
cin >> T;
while (T--){
int N;
cin >> N;
if (N <= 3) {
cout << -1 << "\n";
continue;
}
vector<bool> used(N+1, false);
vector<int> ans;
ans.reserve(N);
// start with 2
ans.push_back(log2(N));
used[log2(N)] = true;
for(int i=1;i<N;i++)
{
int prev=ans.back();
int pick=-1;
for(int j=N;j>1;j--)
{
if(__gcd(prev,j)==1&&prev-j>1&&used[prev-j]==false)
{
pick=prev-j;
break;
}
else if(__gcd(prev,j)==1&&prev+j<=N&&used[prev+j]==false)
{
pick=prev+j;
break;
}
}
if (pick == -1 && !used[1]){
pick = 1;
}
if (pick == -1) break;
ans.push_back(pick);
used[pick] = true;
}
if ((int)ans.size()==N){
for (int x : ans) cout << x << " ";
cout << "\n";
} else {
cout << -1 << "\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 17:24:16
- Judged At
- 2025-06-13 17:24:16
- Judged By
- Score
- 2
- Total Time
- 59ms
- Peak Memory
- 568.0 KiB