# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
259615 | tqbfjotld | Secret Permutation (RMI19_permutation) | C++14 | 3807 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 "permutation.h"
#include <bits/stdc++.h>
using namespace std;
int arr[300];
int n;
vector<int> inv(){
vector<int> ans;
for (int x = 0; x<n; x++){
ans.push_back(0);
}
for (int x = 1; x<=n; x++){
ans[arr[x]-1] = x;
}
return ans;
}
void solve(int N) {
n = N;
for (int x = 1; x<=n; x++){
arr[x] = x;
}
while (true){
if (query(inv())==n-1){
vector<int> ans;
for (int x = 1; x<=n; x++){
ans.push_back(arr[x]);
}
answer(ans);
break;
}
pair<int,int> best = {-1,-1};
int bestv = 999999999;
vector<pair<int,pair<int,int> > >rem;
for (int x = 1; x<=n; x++){
for (int y = x+1; y<=n; y++){
rem.push_back({rand(),{x,y}});
}
}
sort(rem.begin(),rem.end());
int threshold = n*n;
for (int x = 0; x<min(threshold,(int)rem.size()); x++){
swap(arr[rem[x].second.first],arr[rem[x].second.second]);
int t = query(inv());
if (t<bestv){
best = rem[x].second;
bestv = t;
}
swap(arr[rem[x].second.first],arr[rem[x].second.second]);
}
swap(arr[best.first],arr[best.second]);
}
}
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... |