답안 #888428

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
888428 2023-12-17T11:39:33 Z green_gold_dog 순열 (APIO22_perm) C++17
100 / 100
1 ms 388 KB
#include<bits/stdc++.h>
#include "perm.h"
typedef long long ll;
using namespace std;

void add1(vector<int>& ans) {
        for (auto& i : ans) {
                i++;
        }
        ans.push_back(0);
}

void add3(vector<int>& ans) {
        ans.insert(ans.begin() + 2, ans.size());
}

void mul2(vector<int>& ans) {
        ans.push_back(ans.size());
}

std::vector<int> construct_permutation(long long k)
{
        if (k <= 90) {
                vector<int> all;
                for (ll i = 0; i < k - 1; i++) {
                        all.push_back(i);
                }
                reverse(all.begin(), all.end());
                return all;
        }
        vector<ll> all;
        while (k) {
                all.push_back(k & 1);
                k /= 2;
        }
        vector<int> ans;
        ans.push_back(1);
        ans.push_back(0);
        all.pop_back();
        ll lst = all.back();
        all.pop_back();
        if (!lst) {
                lst = all.back();
                all.pop_back();
                add1(ans);
                if (lst) {
                        add1(ans);
                }
        }
        while (!all.empty()) {
                lst = all.back();
                all.pop_back();
                mul2(ans);
                if (lst) {
                        if (!all.empty() && all.back()) {
                                all.pop_back();
                                mul2(ans);
                                add3(ans);
                        } else {
                                add1(ans);
                        }
                }
        }
        return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 388 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 1 ms 348 KB Output is correct