# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
239394 | 2020-06-15T13:20:48 Z | Sorting | Secret Permutation (RMI19_permutation) | C++14 | 2589 ms | 544 KB |
#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 recursion(const vector<int> &v, const vector<int> &arr, vector<int> &ans, vector<int> &vis, int pos){ if(pos == v.size() - 1){ if(abs(ans[0] - ans[v.size() - 1]) == arr[pos]){ vector<int> x(v.size()); for(int i = 0; i < v.size(); ++i) x[v[i] - 1] = ans[i]; answer(x); exit(0); } return; } int choice1 = ans[pos] + arr[pos]; int choice2 = ans[pos] - arr[pos]; if(choice1 <= v.size() && !vis[choice1]){ ans[pos + 1] = choice1; vis[choice1] = true; recursion(v, arr, ans, vis, pos + 1); ans[pos + 1] = 0; vis[choice1] = false; } if(choice2 >= 1 && !vis[choice2]){ ans[pos + 1] = choice2; vis[choice2] = true; recursion(v, arr, ans, vis, pos + 1); ans[pos + 1] = 0; vis[choice2] = false; } } void solve(int n){ vector<int> v; for(int i = 1; i <= n; ++i) v.push_back(i); mt19937 mt(7); random_shuffle(v.begin(), v.end(), [&](int mod){return mt() % mod;}); vector<int> arr(n + 1); for(int i = 0; i < n; ++i){ rotate(v.begin(), v.begin() + 1, v.end()); arr[i] = query(v); } int sum = 0; for(int i = 0; i < n; ++i) sum += arr[i]; sum /= n - 1; for(int i = 0; i < n; ++i) arr[i] = sum - arr[i]; //for(int i = 0; i < n; ++i) // cout << arr[i] << " "; //cout << endl; vector<int> ans(n), vis(n + 1, false); for(int i = 1; i <= n; ++i){ ans[0] = i; vis[i] = true; recursion(v, arr, ans, vis, 0); ans[0] = 0; vis[i] = false; } }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 384 KB | Output is correct |
2 | Correct | 5 ms | 384 KB | Output is correct |
3 | Correct | 5 ms | 384 KB | Output is correct |
4 | Correct | 5 ms | 384 KB | Output is correct |
5 | Correct | 4 ms | 256 KB | Output is correct |
6 | Correct | 5 ms | 256 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 384 KB | Output is correct |
2 | Correct | 5 ms | 384 KB | Output is correct |
3 | Correct | 5 ms | 384 KB | Output is correct |
4 | Correct | 5 ms | 384 KB | Output is correct |
5 | Correct | 4 ms | 256 KB | Output is correct |
6 | Correct | 5 ms | 256 KB | Output is correct |
7 | Correct | 5 ms | 256 KB | Output is correct |
8 | Correct | 5 ms | 288 KB | Output is correct |
9 | Correct | 5 ms | 384 KB | Output is correct |
10 | Correct | 5 ms | 256 KB | Output is correct |
11 | Correct | 6 ms | 384 KB | Output is correct |
12 | Correct | 6 ms | 376 KB | Output is correct |
13 | Correct | 5 ms | 256 KB | Output is correct |
14 | Correct | 5 ms | 380 KB | Output is correct |
15 | Correct | 5 ms | 256 KB | Output is correct |
16 | Correct | 5 ms | 256 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 384 KB | Output is correct |
2 | Correct | 5 ms | 384 KB | Output is correct |
3 | Correct | 5 ms | 384 KB | Output is correct |
4 | Correct | 5 ms | 384 KB | Output is correct |
5 | Correct | 4 ms | 256 KB | Output is correct |
6 | Correct | 5 ms | 256 KB | Output is correct |
7 | Correct | 5 ms | 256 KB | Output is correct |
8 | Correct | 5 ms | 288 KB | Output is correct |
9 | Correct | 5 ms | 384 KB | Output is correct |
10 | Correct | 5 ms | 256 KB | Output is correct |
11 | Correct | 6 ms | 384 KB | Output is correct |
12 | Correct | 6 ms | 376 KB | Output is correct |
13 | Correct | 5 ms | 256 KB | Output is correct |
14 | Correct | 5 ms | 380 KB | Output is correct |
15 | Correct | 5 ms | 256 KB | Output is correct |
16 | Correct | 5 ms | 256 KB | Output is correct |
17 | Correct | 15 ms | 480 KB | Output is correct |
18 | Correct | 2589 ms | 544 KB | Output is correct |
19 | Correct | 1741 ms | 504 KB | Output is correct |
20 | Correct | 150 ms | 376 KB | Output is correct |
21 | Correct | 14 ms | 376 KB | Output is correct |
22 | Correct | 29 ms | 376 KB | Output is correct |
23 | Correct | 93 ms | 384 KB | Output is correct |
24 | Correct | 1763 ms | 388 KB | Output is correct |
25 | Correct | 44 ms | 376 KB | Output is correct |
26 | Correct | 13 ms | 376 KB | Output is correct |