/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Wrong Answer 1ms 532.0 KiB
#2 Wrong Answer 55ms 560.0 KiB

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(3);
        used[3] = 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:20:35
Judged At
2025-06-13 17:20:35
Judged By
Score
0
Total Time
55ms
Peak Memory
560.0 KiB