# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
945236 | 2024-03-13T14:48:21 Z | vjudge1 | Secret Permutation (RMI19_permutation) | C++17 | 706 ms | 452 KB |
#include <bits/stdc++.h> #include "permutation.h" using namespace std; mt19937 rng(1234); #define next amongus pair<int, int> next[434]; int p[333]; int n; vector<int> id; void output() { vector<int> res(n); for (int i = 1; i <= n; i++) res[p[i] - 1] = i; answer(res); return; } bool Try(int i, int index, int cur) { int x = next[index].first; int d = next[index].second; if (i == n - 1) { if (cur + d <= n && p[cur + d] == x) return output(), 1; if (cur - d >= 1 && p[cur - d] == x) return output(), 1; return 0; } int random = rng() & 1; int t = 2; while (t--) { if (random) { if (cur + d <= n && p[cur + d] == 0) { p[cur + d] = x; if (Try(i + 1, x, cur + d)) return 1; p[cur + d] = 0; } } else { if (cur - d >= 1 && p[cur - d] == 0) { p[cur - d] = x; if (Try(i + 1, x, cur - d)) return 1; p[cur - d] = 0; } } random ^= 1; } return 0; } void solve(int N) { n = N; id = vector<int>(N); iota(id.begin(), id.end(), 1); shuffle(id.begin(), id.end(), rng); vector<int> a(N); for (int i = 0; i < N; i++) { a[i] = query(id); id.emplace_back(id[0]); id.erase(id.begin()); } int64_t sum = accumulate(a.begin(), a.end(), 0ll); sum /= N - 1; for (int i = 0; i < N; i++) { /// diff between p[id[i]] and p[id[i - 1]] next[id[i]] = {(id[i ? i - 1 : N - 1]), sum - a[i]}; } for (int i = 1; i <= N; i++) { /// try p[id[0]] = i; p[i] = id[0]; if (Try(0, id[0], i)) break; p[i] = 0; } }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 344 KB | Output is correct |
2 | Correct | 0 ms | 344 KB | Output is correct |
3 | Correct | 0 ms | 344 KB | Output is correct |
4 | Correct | 0 ms | 344 KB | Output is correct |
5 | Correct | 0 ms | 344 KB | Output is correct |
6 | Correct | 0 ms | 344 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 344 KB | Output is correct |
2 | Correct | 0 ms | 344 KB | Output is correct |
3 | Correct | 0 ms | 344 KB | Output is correct |
4 | Correct | 0 ms | 344 KB | Output is correct |
5 | Correct | 0 ms | 344 KB | Output is correct |
6 | Correct | 0 ms | 344 KB | Output is correct |
7 | Correct | 1 ms | 444 KB | Output is correct |
8 | Correct | 1 ms | 344 KB | Output is correct |
9 | Correct | 1 ms | 448 KB | Output is correct |
10 | Correct | 1 ms | 344 KB | Output is correct |
11 | Correct | 1 ms | 344 KB | Output is correct |
12 | Correct | 1 ms | 344 KB | Output is correct |
13 | Correct | 1 ms | 444 KB | Output is correct |
14 | Correct | 1 ms | 344 KB | Output is correct |
15 | Correct | 1 ms | 344 KB | Output is correct |
16 | Correct | 1 ms | 344 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 344 KB | Output is correct |
2 | Correct | 0 ms | 344 KB | Output is correct |
3 | Correct | 0 ms | 344 KB | Output is correct |
4 | Correct | 0 ms | 344 KB | Output is correct |
5 | Correct | 0 ms | 344 KB | Output is correct |
6 | Correct | 0 ms | 344 KB | Output is correct |
7 | Correct | 1 ms | 444 KB | Output is correct |
8 | Correct | 1 ms | 344 KB | Output is correct |
9 | Correct | 1 ms | 448 KB | Output is correct |
10 | Correct | 1 ms | 344 KB | Output is correct |
11 | Correct | 1 ms | 344 KB | Output is correct |
12 | Correct | 1 ms | 344 KB | Output is correct |
13 | Correct | 1 ms | 444 KB | Output is correct |
14 | Correct | 1 ms | 344 KB | Output is correct |
15 | Correct | 1 ms | 344 KB | Output is correct |
16 | Correct | 1 ms | 344 KB | Output is correct |
17 | Correct | 10 ms | 452 KB | Output is correct |
18 | Correct | 12 ms | 452 KB | Output is correct |
19 | Correct | 10 ms | 452 KB | Output is correct |
20 | Correct | 246 ms | 448 KB | Output is correct |
21 | Correct | 7 ms | 452 KB | Output is correct |
22 | Correct | 183 ms | 452 KB | Output is correct |
23 | Correct | 54 ms | 444 KB | Output is correct |
24 | Correct | 706 ms | 448 KB | Output is correct |
25 | Correct | 7 ms | 452 KB | Output is correct |
26 | Correct | 97 ms | 452 KB | Output is correct |