# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
637790 | ogibogi2004 | Secret Permutation (RMI19_permutation) | C++14 | 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 "permutationc.h"
#include<bits/stdc++.h>
using namespace std;
mt19937 mt(69);
/*vector<int>p;
int query(vector<int>v)
{
int ans=0;
for(int i=1;i<v.size();i++)
{
ans+=abs(p[v[i]]-p[v[i-1]]);
}
return ans;
}
void answer(vector<int>v)
{
for(auto xd:v)cout<<xd<<" ";
cout<<endl;
}*/
int[] conv(vector<int>v)
{
int ret[v.size()];
for(int i=0;i<v.size();i++)ret[i]=v[i];
return ret;
}
int val[256];
int dif1[256];
int dif2[256];
int c[256];
int n;
void solve(int N)
{
n=N;
vector<int>v1;
for(int i=0;i<n;i++)v1.push_back(i);
vector<int>answers;
answers.push_back(query(v1));
for(int i=1;i<n;i++)
{
v1.clear();
for(int j=i;j<n;j++)v1.push_back(j);
for(int j=0;j<i;j++)v1.push_back(j);
answers.push_back(query(conv(v1)));
}
int sum=0;
for(auto xd:answers)sum+=xd;
sum/=(n-1);
//cout<<sum<<endl;
for(int i=0;i<n;i++)
{
dif1[i]=sum-answers[i];
}
v1.clear();
answers.clear();
vector<int>v2;
for(int i=0;i<n;i+=2)v2.push_back(i);
for(int i=1;i<n;i+=2)v2.push_back(i);
for(int i=0;i<v2.size();i++)
{
v1.clear();
for(int j=i;j<v2.size();j++)v1.push_back(v2[j]);
for(int j=0;j<i;j++)v1.push_back(v2[j]);
answers.push_back(query(conv(v1)));
}
sum=0;
for(auto xd:answers)sum+=xd;
sum/=(n-1);
for(int i=0;i<v2.size();i++)
{
dif2[v2[i]]=sum-answers[i];
}
vector<int>ans(n,0);
ans[1]=ans[0]+dif1[1];
c[1]=1;
for(int i=2;i<ans.size();i++)
{
if(dif2[i]==dif1[i-1]+dif1[i])
{
c[i]=c[i-1];
}
else c[i]=-c[i-1];
ans[i]=ans[i-1]+c[i]*dif1[i];
}
int minans=0;
for(int i=0;i<ans.size();i++)minans=min(minans,ans[i]);
for(int i=0;i<ans.size();i++)
{
ans[i]-=minans;
ans[i]+=1;
}
/*cout<<"difs:\n";
for(int i=0;i<n;i++)
{
cout<<dif1[i]<<" ";
}
cout<<endl;
for(int i=0;i<n;i++)
{
cout<<dif2[i]<<" ";
}
cout<<endl;
cout<<endl;*/
answer(ans);
}
/*int main()
{
int N;
cin>>N;
for(int i=0;i<N;i++)
{
int x;
cin>>x;
p.push_back(x);
}
solve(N);
}*/