제출 #1118736

#제출 시각아이디문제언어결과실행 시간메모리
1118736Username_taken12Permutation (APIO22_perm)C++17
컴파일 에러
0 ms0 KiB

#include <bits/stdc++.h>
using namespace std;

vector<int> construct_permuation(long long k) {
	//int cnt = std::popcount((unsigned long long) k); 
	int cnt=0;
	int size =0;
	long long t=k;
	while(t>0){
		size++;
		t/=2;
		if(t%2==1)
			cnt++;
	}
	int len = size+cnt-1;
	int h=len;
	int a =1;
	vector<int> out;
	while(k>1){
		if(k%2==1)
			out.push_back(h--);
		out.push_back(a++);
		k/=2;
	}
	return out;
}

int main() {
	long long k; cin>>k;
	vector<int> ans = construct_permuation(k);
	for(int i=0; i<ans.size(); i++)
		cout<<ans[i]<<" ";
	cout<<endl;
}

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

perm.cpp: In function 'int main()':
perm.cpp:32:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   32 |  for(int i=0; i<ans.size(); i++)
      |               ~^~~~~~~~~~~
/usr/bin/ld: /tmp/ccrjR4pj.o: in function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/ccOpRQVf.o:perm.cpp:(.text.startup+0x0): first defined here
/usr/bin/ld: /tmp/ccrjR4pj.o: in function `main':
grader.cpp:(.text.startup+0x240): undefined reference to `construct_permutation(long long)'
collect2: error: ld returned 1 exit status