# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
856774 | Tenis0206 | Secret Permutation (RMI19_permutation) | C++14 | 0 ms | 344 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>
#ifndef home
#include "permutation.h"
#endif // home
using namespace std;
const int nmax = 256;
int n;
#ifdef home
vector<int> p;
void debug(vector<int> c)
{
for(auto it : c)
{
cerr<<it<<' ';
}
cerr<<'\n';
}
void answer(vector<int> rez)
{
for(auto it : rez)
{
cout<<it<<' ';
}
cout<<'\n';
}
int query(vector<int> v)
{
int sum = 0;
for(int i=1;i<n;i++)
{
sum += abs(p[v[i - 1] - 1] - p[v[i] - 1]);
}
return sum;
}
#endif // home
vector<int> find_rev(vector<int> r)
{
vector<int> rez(n);
for(int i=0;i<n;i++)
{
rez[r[i] - 1] = i + 1;
}
return rez;
}
void solve(int N)
{
n = N;
vector<int> r(n);
for(int i=0;i<n;i++)
{
r[i] = i + 1;
}
int val = query(r);
for(int i=1;i<=n;i++)
{
for(int j=i+1;j<=n;j++)
{
swap(r[i - 1], r[j - 1]);
int cur = query(r);
if(cur < val)
{
val = cur;
}
else
{
swap(r[i - 1], r[j - 1]);
}
}
}
vector<int> rez = find_rev(r);
answer(rez);
}
#ifdef home
int main()
{
freopen("nr.in","r",stdin);
freopen("nr.out","w",stdout);
int nn;
cin>>nn;
p.resize(nn);
for(int i=1;i<=nn;i++)
{
cin>>p[i - 1];
}
solve(nn);
return 0;
}
#endif // home
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |