Submission

Status:

(PP)(PPPPP)(PPPPPP)(PP)

Subtask/Task Score:

{20/20}{40/40}{30/30}{10/10}

Score: 100

User: Test

Problemset: สร้างคู่ผกผัน (Inversion)

Language: cpp

Time: 0.002 second

Submitted On: 2026-03-17 20:20:13

#include <vector>
#include <deque>
#include "inversion.h"
using namespace std;

std::vector<int> inversion(int N, int S) {
    vector<int> choose(N + 1, 0);

    // ???͡?Ţ x ???з???? inversion ???? x-1
    for (int x = N; x >= 1; x--){
        if (S >= x - 1) {
            choose[x] = 1;
            S -= (x - 1);
        }
    }

    deque<int> dq;

    // ???ҧ permutation
    for (int x = 1; x <= N; x++) {
        if (choose[x]) dq.push_front(x); // ???͡ -> ???˹??
        else dq.push_back(x);            // ??????͡ -> ??????
    }

    vector<int> ans;
    for (int x : dq) ans.push_back(x);

    return ans;
}