# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
238894 | Sorting | Secret Permutation (RMI19_permutation) | C++14 | 5 ms | 384 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>
#include "permutationc.h"
using namespace std;
int query(int v[]);
int query(vector<int> v);
void answer(int v[]);
void answer(vector<int> v);
void solve(int n){
vector<int> v;
for(int i = 1; i <= n; ++i)
v.push_back(i);
int best_diff = 0, best_idx = 1;
for(int i = 2; i < n; ++i){
swap(v[i], v[n - 1]);
int curr = query(v);
swap(v[1], v[n - 1]);
int after = query(v);
swap(v[1], v[n - 1]);
swap(v[i], v[n - 1]);
int curr_diff = after - curr;
if(curr_diff > best_diff){
best_diff = curr_diff;
best_idx = i;
}
}
int best_val = best_idx + 1;
//cout << best_idx << " best_idx" << endl;
swap(v[best_idx], v[0]);
vector<int> diff(n);
diff[1] = 0;
for(int i = 2; i < n; ++i){
swap(v[i], v[n - 1]);
int curr = query(v);
swap(v[1], v[n - 1]);
int after = query(v);
swap(v[1], v[n - 1]);
swap(v[i], v[n - 1]);
diff[i] = after - curr;
}
int min_diff = 100000;
for(int i = 1; i < n; ++i)
min_diff = min(diff[i], min_diff);
for(int i = 1; i < n; ++i){
diff[i] -= min_diff;
diff[i] += 2;
}
diff[0] = 1;
swap(diff[best_idx], diff[0]);
answer(diff);
}
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... |