Submission #856774

#TimeUsernameProblemLanguageResultExecution timeMemory
856774Tenis0206Secret Permutation (RMI19_permutation)C++14
0 / 100
0 ms344 KiB
#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 (stderr)

stub.cpp: In function 'int query(int*)':
stub.cpp:15:9: warning: ignoring return value of 'int fscanf(FILE*, const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   15 |   fscanf(stdin, "%d", &x);
      |   ~~~~~~^~~~~~~~~~~~~~~~~
stub.cpp: In function 'int main(int, char**)':
stub.cpp:48:9: warning: ignoring return value of 'int fscanf(FILE*, const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   48 |   fscanf(stdin, "%d", &N);
      |   ~~~~~~^~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...