# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
644245 | Karuk | Secret Permutation (RMI19_permutation) | C++14 | 0 ms | 0 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#include "permutationc.h"
using namespace std;
void solve(int n) {
vector<int>a(n);
for(int i=1;i<=n;i++) {
a[i-1]=i;
}
int maxres=0,maxind=-1;
for(int i=1;i<n;i++) {
reverse(a.begin(),a.begin()+i-1);
int c=query(a);
reverse(a.begin(),a.begin()+i-1);
if(c>maxres){maxres=c;maxind=a[i];}
}
swap(a[0],a[maxind]);
maxres=0;
maxind=-1;
vector<pair<int,int> >v;
for(int i=1;i<n;i++) {
reverse(a.begin(),a.begin()+i-1);
int c=query(a);
reverse(a.begin(),a.begin()+i-1);
v.push_back({c,a[i]});
}
vector<int>ans(n,-1);
sort(v.begin(),v.end());
ans[a[0]]=1;
for(int i=2;i<=n;i++) {
ans[v[i-2].second]=i;
}
answer(ans);
}