/ SeriousOJ /

Record Detail

Runtime Error


  
# Status Time Cost Memory Cost
#1 Runtime Error 1ms 540.0 KiB
#2 Runtime Error 1074ms 5.473 MiB

Code

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

#ifdef LOCAL
#include "debug.h"
#else
#define dbg(...) 42
#endif

#define int long long

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

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

    vector<vector<int>> adj(n + 1);
    for (int u = 1; u <= n; u++) {
        for (int v = u + 2; v <= n; v++) {
            if (gcd(v, u) == 1 && abs(u - v) > 1) {
                adj[u].push_back(v);
                adj[v].push_back(u);
            }
        }
    }

    for (int i = 1; i <= n; i++) {
        queue<int> q;
        q.push(i);
        vector<int> res;
        vector<bool> vis(n + 1);
        vis[i] = 1;
        while (!q.empty()) {
            int u = q.front();
            q.pop();
            res.push_back(u);
            for (auto v : adj[u]) {
                if (!vis[v]) {
                    vis[v] = 1;
                    q.push(v);
                }
            }
        }
        bool is = 0;
        for (int j = 1; j < n; j++) {
            if (gcd(res[j], res[j - 1]) == 1 && abs(res[j] - res[j - 1]) > 1) {
            }
            else {
                is = 1;
                break;
            }
        }
        if (!is) {
            for (auto x : res) cout << x << ' '; cout << '\n';
        }
    }
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int t;
    cin >> t;

    while (t--) {
        solve();
    }

    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 15:58:05
Judged At
2025-06-13 15:58:05
Judged By
Score
0
Total Time
1074ms
Peak Memory
5.473 MiB