# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
856774 | 2023-10-04T14:21:31 Z | Tenis0206 | Secret Permutation (RMI19_permutation) | C++14 | 0 ms | 344 KB |
#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
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 0 ms | 344 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 0 ms | 344 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 0 ms | 344 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |