제출 #982866

#제출 시각아이디문제언어결과실행 시간메모리
982866vjudge1순열 (APIO22_perm)C++17
컴파일 에러
0 ms0 KiB
#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; } int main() { long long k; cin>>k; vector <int> holi = construct_permutation(k); for(auto it: holi) cout<<it<<' '; }

컴파일 시 표준 에러 (stderr) 메시지

perm.cpp: In function 'std::vector<int> construct_permutation(long long int)':
perm.cpp:25:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   25 |     for(int i=0; i<arr.size(); i++, x++)
      |                  ~^~~~~~~~~~~
perm.cpp:30:38: warning: 'x' may be used uninitialized in this function [-Wmaybe-uninitialized]
   30 |     for(int j=0, k=x-1, l=0, p = 0; j<x; j++, p++){
      |                                     ~^~
/usr/bin/ld: /tmp/ccn7s6KM.o: in function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/cc963YYP.o:perm.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status