# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
714238 | vjudge1 | Art Collections (BOI22_art) | C++17 | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define size(v) v.size()
#define all(v) v.begin(), v.end()
#define INF 2e9
#define f first
#define s second
using namespace std;
int N;
vector<int>a, in1, in2;
int publish(std::vector<int>R){
for(int i = 0; i < N; i++){
in2[R[i]] = i;
}
int cnt = 0;
for(int i = 0; i < N; ++i){
for(int j = 0; j < N; j++){
if(a[i] != R[j]){
if((in1[R[j]] > in1[a[i]]) && (in2[R[j]] < in2[a[i]])){
cnt++;
}
}
}
}
return cnt;
}
void answer(std::vector<int>R){
for(int i : R){
cout << i << " ";
}
cout << "\n";
}
void solve(int N){
vector<int>R(N);
R = a;
sort(all(R));
do{
if(!publish(R)){
answer(R);
return;
}
}
while(next_permutation(all(R)));
}
void grader(){
cin >> N;
a.resize(N), in1.resize(N), in2.resize(N);
for(int i = 0; i < N; ++i){
cin >> a[i];
in1[a[i]] = i;
}
solve(N);
}
int main()
{
grader();
}