답안 #730837

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
730837 2023-04-26T13:52:18 Z Jarif_Rahman 순열 (APIO22_perm) C++17
91.3333 / 100
2 ms 340 KB
#include "perm.h"
#include <bits/stdc++.h>
#define pb push_back
#define f first
#define sc second
using namespace std;
typedef long long int ll;
typedef string str;


vector<int> construct_permutation(ll k){
    k--;

    vector<int> sth;
    int n = 0;

    int P = 0;
    while((1LL<<P)-1 <= k) P++;
    P--;
    k-=(1LL<<P)-1;
    n+=P;

    vector<int> s(P);
    ll ss = 0;

    for(int i = P-1; i > 0; i--){
        int p = 1;
        while((1LL<<p)-1 + ((1LL<<p)-1)*((1LL<<i)-1) <= k) p++;
        p--;
        k-=(1LL<<p)-1 + ((1LL<<p)-1)*((1LL<<i)-1);
        s[i] = p;
        n+=p; 
    }

    while(k > 0){
        int p = 0;
        while((1LL<<p)-1 <= k) p++;
        p--;
        k-=(1LL<<p)-1;
        sth.pb(p);
        n+=p;
    }

    vector<int> ans;
    for(int x: sth){
        for(int i = n-x; i < n; i++) ans.pb(i);
        n-=x;
    }

    vector<int> anss, pp;
    for(int i = n-P; i < n; i++) pp.pb(i);
    n-=P;
    if(!pp.empty()) anss.pb(pp[0]);
    for(int i = 1; i < P; i++){
        while(s[P-i]--) anss.pb(n-1), n--;
        anss.pb(pp[i]);
    }

    ans.insert(ans.end(), anss.begin(), anss.end());

    return ans;
}

Compilation message

perm.cpp: In function 'std::vector<int> construct_permutation(ll)':
perm.cpp:24:8: warning: unused variable 'ss' [-Wunused-variable]
   24 |     ll ss = 0;
      |        ^~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Partially correct 2 ms 340 KB Partially correct
6 Correct 2 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Partially correct 2 ms 340 KB Partially correct
9 Correct 1 ms 340 KB Output is correct
10 Partially correct 2 ms 340 KB Partially correct
11 Partially correct 2 ms 340 KB Partially correct
12 Partially correct 2 ms 340 KB Partially correct
13 Partially correct 2 ms 340 KB Partially correct