# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
685449 | 2023-01-24T11:38:25 Z | dranaya_dusha | Secret Permutation (RMI19_permutation) | C++17 | 1 ms | 336 KB |
//#pragma GCC optimize ("Ofast") #include <bits/stdc++.h> ////#define int long long //#define mp make_pair //#define pb push_back //#define fi first //#define se second //#define pii pair <int, int> #include "permutation.h" using namespace std; vector<int> ans; vector<int> used; bool check (vector<int> &q, vector<int> &v, int p, int n) { used[ans[v[p]-1]]=1; if (p==n-1 && abs(ans[v[p]-1] - ans[v[0]-1] ) == q[n-1]) { answer(ans); exit(0); } else{ if (ans[v[p]-1]+q[p]<=n && !used[ans[v[p]-1]+q[p]]){ ans[v[p+1]-1]=ans[v[p]-1]+q[p]; // used[ans[v[p]-1]+q[i]]=1; check(q, v, p+1, n); } else if (ans[v[p]-1]-q[p]>0 && !used[ans[v[p]-1]-q[p]]) { ans[v[p+1]-1]=ans[v[p]-1]-q[p]; check(q, v, p+1, n); // used[ans[v[p]-1]-q[p]]=1; } used[ans[v[p]-1]]=0; ans[v[p]-1]=0; } } void solve(int n) { vector<int> v; for (int i=1; i<=n; i++) v.push_back(i); srand(time(NULL)); random_shuffle(v.begin(), v.end()); vector<int> q(n); for(int i=0;i<n;i++){ rotate(v.begin(),v.begin()+1,v.end()); q[i] = query(v); } // for (int i=0; i<n; i++) // cout << q[i] << ' '; rotate(v.begin(),v.begin()+1,v.end()); int sum=0; for(int i=0;i<n;i++){ sum+=q[i]; } sum/=(n-1); for(int i=0;i<n;i++) q[i]=(sum-q[i]); rotate(q.begin(),q.begin()+1,q.end()); ans.assign(n, 0); // for (int i=0; i<n; i++) // cout << q[i] << ' '; // cout << endl; // for (int i=0; i<n; i++) // cout << v[i] << ' '; // cout << endl; for (int i=1; i<=n; i++) { used.assign(n+1, 0); ans.assign(n, 0); ans[v[0]-1]=i; check(q, v, 0, n); } }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 1 ms | 336 KB | Execution killed with signal 11 |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 1 ms | 336 KB | Execution killed with signal 11 |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 1 ms | 336 KB | Execution killed with signal 11 |
2 | Halted | 0 ms | 0 KB | - |