/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 532.0 KiB
#2 Accepted 2ms 532.0 KiB

Code

#include <bits/stdc++.h>
#define ll long long
#define MODD 1000000007
#define MAXN 102
using namespace std;



int main() {
    int T;
    cin>> T;
    while (T--) {
        int N;
        cin>>N;
        set<int> S;
        for(int i=1;i<=N;i++) {
            S.insert(i);
        }
        vector<int> V;
        V.reserve(N);
        for(int i=1;i<=N;i++) {
            bool found = false;
            for(int x : S) {
                if (x != i) {
                    found= true;
                    V.push_back(x);
                    S.erase(x);
                    break;
                }
            }
            if (!found) {
                V.push_back(*S.begin());
                S.erase(S.begin());
            }
        }

        if (V.back()==N) {
            swap(V[N-1], V[N-2]);
        }
        for (int x : V) {
            cout << x << " ";
        }
        cout << endl;
        S.clear();
    }
}

Information

Submit By
Type
Submission
Problem
P1210 A. Smallest Permutation
Contest
Educational Round 1
Language
C++17 (G++ 13.2.0)
Submit At
2025-07-14 15:50:40
Judged At
2025-07-14 15:50:41
Judged By
Score
100
Total Time
2ms
Peak Memory
532.0 KiB