/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 540.0 KiB

Code

#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
using namespace std;
// using namespace __gnu_pbds;
#define int long long
// #define endl "\n"
#define tej ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define mod 1000000007
#define sum(zee) (accumulate((zee).begin(), (zee).end(), 0LL))
#define mine(zee) (*min_element((zee).begin(), (zee).end()))
#define maxe(zee) (*max_element((zee).begin(), (zee).end()))
#define mini(zee) (min_element((zee).begin(), (zee).end()) - (zee).begin())
#define maxi(zee) (max_element((zee).begin(), (zee).end()) - (zee).begin())
#define cnt(zee, x) (count((zee).begin(), (zee).end(), (x)))
#define lob(zee, x) (*lower_bound((zee).begin(), (zee).end(), (x)))
#define upb(zee, x) (*upper_bound((zee).begin(), (zee).end(), (x)))
#define ojs() \
    freopen("input.txt", "r", stdin); \
    freopen("output.txt", "w", stdout);

// typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> oset;

#define order_of_key(x) oset.order_of_key(x) // Number of elements less than x
#define find_by_order(k) *oset.find_by_order(k) // K-th smallest element (0-based index)

#define oin(x) oset.insert(x);      // O(log n)
#define oer(x) oset.erase(x);       // O(log n)

int a[1]={0};
class FastInput {
public:
    FastInput() {
        ios::sync_with_stdio(false);
        cin.tie(NULL);
    }

    int nextInt() {
        int x;
        cin >> x;
        return x;
    }

    long long nextLong() {
        long long x;
        cin >> x;
        return x;
    }
};

FastInput in;
//ostream &output = ot;
int N;
vector<vector<int>> adj;
vector<bool> used;
vector<int> path;          
bool fd;
void dfs(int depth) {
    if(fd) return; 
    if(depth == N) {
        fd = true;
        return;
    }
    int last = path.back();
    for (int nxt : adj[last]) {
        if(!used[nxt]) {
            used[nxt] = true;
            path.push_back(nxt);
            dfs(depth + 1);
            if(fd) return;
            path.pop_back();
            used[nxt] = false;
        }
    }
}
void solve(int test)
{
    // Your sol here
    int n= in.nextInt();
    if(n == 2 || n == 3 || n == 4 || n == 6){
        cout << -1 << "\n";
        return;
    }
 
    vector<int> ans;
    if(n % 2 == 1){
        ans = {2, 5, 3, 1, 4};
        for (int i = 6; i <= n; i++){
            if(i % 2 == 0)
                ans.push_back(i);
            else
                ans.insert(ans.begin(), i);
        }
    } else {
        ans = {2, 5, 8, 3, 7, 4, 1, 6}; 
        for (int i = 9; i <= n; i++){
            if(i % 2 == 0)
                ans.push_back(i);
            else
                ans.insert(ans.begin(), i);
        }
    }
    for (int x : ans)
        cout << x << " ";
    cout << "\n";
}

// Main function
signed main() {
    tej;
    // #ifndef ONLINE_JUDGE
    //     ojs();
    // #endif

    int test=1;
    test=in.nextInt();
    while(test--) {
        solve(test);
    }
    return 0;
}

Information

Submit By
Type
Pretest
Problem
P1203 D. Roy Loves Permutation
Language
C++17 (G++ 13.2.0)
Submit At
2025-06-13 15:50:12
Judged At
2025-06-13 15:50:12
Judged By
Score
10
Total Time
1ms
Peak Memory
540.0 KiB