# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
941878 | abcvuitunggio | Secret Permutation (RMI19_permutation) | C++17 | 3015 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.
//#define NAM
#ifndef NAM
#include "permutation.h"
#endif // NAM
#include <bits/stdc++.h>
using namespace std;
#ifdef NAM
int n,cnt_q=0;
vector <int> p,q;
int query(vector <int> v){
auto v2=v;
sort(v2.begin(),v2.end());
int ch=1;
for (int i=0;i<v2.size();i++)
ch&=(v2[i]==i+1);
if (v2.size()!=n||!ch){
cout << "Error: Not a permutation";
exit(0);
}
cnt_q++;
int res=0;
for (int i=0;i<n-1;i++)
res+=abs(p[v[i]-1]-p[v[i+1]-1]);
return res;
}
void answer(vector <int> v){
if (v!=p&&v!=q)
cout << "Wrong Answer";
else{
cout << "Correct\n";
cout << "You asked " << cnt_q << " queries";
}
}
#endif // NAM
void solve(int n){
vector <int> cur;
for (int i=1;i<=n;i++)
cur.push_back(i);
int x=query(cur);
while (x>n-1){
for (int i=0;i<n;i++)
for (int j=i+1;j<n;j++){
reverse(cur.begin()+i,cur.begin()+j+1);
int y=query(cur);
if (y<x)
x=y;
else
reverse(cur.begin()+i,cur.begin()+j+1);
}
}
vector <int> ans(n,0);
for (int i=1;i<=n;i++)
ans[cur[i-1]-1]=i;
answer(ans);
}
#ifdef NAM
int main(){
cin >> n;
for (int i=1;i<=n;i++)
p.push_back(i);
random_shuffle(p.begin(),p.end());
for (int i:p)
q.push_back(n-i+1);
solve(n);
}
#endif // NAM
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... |