이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "perm.h"
#include<bits/stdc++.h>
using namespace std;
std::vector<int> construct_permutation(long long k)
{
if(k==2) return {0};
else if(k==3) return {1, 0};
else if(k==4) return {0, 1};
else if(k==5) return {2, 0, 1};
else if(k==6) return {0, 2, 1};
else if(k==7) return {2, 1, 3, 0};
else {
vector<int> p = construct_permutation(k/4);
if(k%4 == 0) { // *4
p.push_back(p.size());
p.push_back(p.size());
return p;
} else if(k%4==1) { // *4+1
p.push_back(p.size());
p.push_back(p.size());
p.push_back(0);
for(int i=p.size()-2; i>=0; i--) p[i]++;
return p;
} else if(k%4==2) { // *4+2
for(int i=0; i<p.size(); i++) p[i]++;
int t = p.size();
p.push_back(t+1);
p.push_back(0);
p.push_back(t+2);
return p;
} else {
int pos1 = -1, pos0 = -1;
for(int i=0; i<p.size(); i++) {
if(p[i]==1) pos1 = i;
if(p[i]==0) pos0 = i;
}
if(pos1 < pos0 && pos1!=-1) {
p.push_back(p.size());
p.push_back(p.size());
for(int i=0; i<p.size(); i++) if(p[i]>1) p[i]++;
p.push_back(2);
return p;
} else {
for(int i=0; i<p.size(); i++) p[i]+=2;
int t = p.size()+2;
p.push_back(t);
p.push_back(1);
p.push_back(t+1);
p.push_back(0);
return p;
}
}
}
}
컴파일 시 표준 에러 (stderr) 메시지
perm.cpp: In function 'std::vector<int> construct_permutation(long long int)':
perm.cpp:26:21: 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<p.size(); i++) p[i]++;
| ~^~~~~~~~~
perm.cpp:34:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
34 | for(int i=0; i<p.size(); i++) {
| ~^~~~~~~~~
perm.cpp:41:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
41 | for(int i=0; i<p.size(); i++) if(p[i]>1) p[i]++;
| ~^~~~~~~~~
perm.cpp:45:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
45 | for(int i=0; i<p.size(); i++) p[i]+=2;
| ~^~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |