/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Wrong Answer 1ms 540.0 KiB
#2 Wrong Answer 1ms 540.0 KiB

Code

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

int gcd(int a, int b) {
    while (b) {
        a %= b;
        swap(a, b);
    }
    return a;
}

bool is_valid(const vector<int>& a) {
    for (int i = 0; i + 1 < a.size(); i++) {
        if (gcd(a[i], a[i + 1]) != 1) return false;
        if (abs(a[i] - a[i + 1]) <= 1) return false;
    }
    return true;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int t;
    cin >> t;
    while (t--) {
        int n;
        cin >> n;
        vector<int> a;
        for (int i = 1; i <= n; i += 2) a.push_back(i);
        for (int i = 2; i <= n; i += 2) a.push_back(i);
        if (is_valid(a)) {
            for (int x : a) cout << x << " ";
            cout << "\n";
        } else {
            a.clear();
            for (int i = 2; i <= n; i += 2) a.push_back(i);
            for (int i = 1; i <= n; i += 2) a.push_back(i);
            if (is_valid(a)) {
                for (int x : a) cout << x << " ";
                cout << "\n";
            } else {
                cout << "-1\n";
            }
        }
    }
}

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:53:12
Judged At
2025-06-13 17:53:12
Judged By
Score
0
Total Time
1ms
Peak Memory
540.0 KiB