답안 #982869

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
982869 2024-05-14T21:50:33 Z vjudge1 순열 (APIO22_perm) C++17
0 / 100
0 ms 344 KB
#include "perm.h"
#include <bits/stdc++.h>
using namespace std;

vector <int> construct_permutation(long long k) {

    k--;

    vector <int> arr;

    for (long long i = 1, j = 0; k; j++ , i*= 2) {
        if (k % 2 == 1) {
            arr.push_back(1);
            k /= 2;
        } else {
            arr.push_back(2);
            k -= 2;
            k /= 2;
        }
    }

    //for(auto it: arr) cout<<it<<' ';

    int x;

    for(int i=0; i<arr.size(); i++, x++)
            if(arr[i] == 2) x++;

    vector <int> ans(x);

    for(int j=0, k=x-1, l=0, p = 0; j<x; j++, p++){

        if(arr[p] == 1){
            ans[j] = l;
            l++;
        } else {
            ans[j] = k;
            ans[j+1] = l;
            k--;
            l++;
            j++;
        }

    }

    return ans;

}

Compilation message

perm.cpp: In function 'std::vector<int> construct_permutation(long long int)':
perm.cpp:26:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   26 |     for(int i=0; i<arr.size(); i++, x++)
      |                  ~^~~~~~~~~~~
perm.cpp:31:38: warning: 'x' may be used uninitialized in this function [-Wmaybe-uninitialized]
   31 |     for(int j=0, k=x-1, l=0, p = 0; j<x; j++, p++){
      |                                     ~^~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -