이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "bits/stdc++.h"
using namespace std;
// #include "perm.h"
std::vector<int> construct_permutation(long long S)
{
vector<int> v;
bool emp=1;
int t=0;
for(int i=30; i>=0; i--){
int d=(S/(1LL<<(2*i)))%4;
if(emp){
if(!d) continue;
if(d==1) {}
if(d==2) v={0};
if(d==3) v={1,0};
emp=0;
continue;
}
int mx=(v.size()?*max_element(v.begin(), v.end()):0);
int mn=(v.size()?*min_element(v.begin(), v.end()):0);
if(d==0){
v.push_back(mx+1);
v.push_back(mx+2);
}
if(d==1){
v.push_back(mx+1);
v.push_back(mx+2);
v.push_back(mn-1);
}
if(d==2){
v.push_back(mx+1);
v.push_back(mn-1);
v.push_back(mx+2);
}
if(d==3){
int i0=-1,i1=-1;
for(int j=0; j<v.size(); j++){
if(v[j]==mn) i0=j;
if(v[j]==mn+1) i1=j;
}
if(i1!=-1 && i0!=-1 && i1<i0){
v.push_back(mx+1);
v.push_back(mx+2);
v[i0]--, v[i1]--;
v.push_back(mn+1);
}
else{
v.push_back(mx+1);
v.push_back(mn-1);
v.push_back(mx+2);
v.push_back(mn-2);
}
}
}
vector<int> a=v;
sort(a.begin(), a.end());
for(int &x:v) x=lower_bound(a.begin(), a.end(), x)-a.begin();
return v;
}
// int main(){
// cin.tie(0)->sync_with_stdio(0);
// int k; cin >> k;
// for(int x:construct_permutation(k)) cout << x << " ";
// }
컴파일 시 표준 에러 (stderr) 메시지
perm.cpp: In function 'std::vector<int> construct_permutation(long long int)':
perm.cpp:39:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
39 | for(int j=0; j<v.size(); j++){
| ~^~~~~~~~~
perm.cpp:10:9: warning: unused variable 't' [-Wunused-variable]
10 | int t=0;
| ^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |