# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
236301 | 2020-06-01T07:40:33 Z | tjd229 | Secret Permutation (RMI19_permutation) | C++14 | 5000 ms | 432 KB |
#include "permutation.h" #include <vector> #include <algorithm> #include <random> #include <time.h> using namespace std; int Tx[257], x[257]; int use[257]; int _N; #include <stdio.h> void print(int *p) { for (int i = 1; i <= _N; ++i) printf("%d ", p[i]); puts(""); } bool recon(int ix, vector<int> &P) { int bk = P.back(); // if (ix == _N) { int d = bk - P[0]; if (d < 0) d = -d; return d == x[1]; } int nxt = bk + x[ix + 1]; if (nxt <= _N && use[nxt] == 0) { use[nxt] = 1; P.push_back(nxt); if (recon(ix + 1, P)) return 1; P.pop_back(); use[nxt] = 0; } nxt = bk - x[ix + 1]; if (nxt > 0 && use[nxt] == 0) { use[nxt] = 1; P.push_back(nxt); if (recon(ix + 1, P)) return 1; P.pop_back(); use[nxt] = 0; } return 0; } void solve(int N) { _N = N; int sum = 0; vector<int> P, V; for (int i = 1; i <= N; ++i) V.push_back(i); /*mt19937 g(random_device); shuffle(V.begin(), V.end(),g);*/ srand(time(0)); random_shuffle(V.begin(), V.end()); for (int i = 1; i <= N; ++i) { Tx[i] = query(V); sum += Tx[i]; use[i] = 0; rotate(V.begin(), V.begin() + 1, V.end()); } int T = sum / (N - 1); for (int i = 1; i <= N; ++i) x[i] = T - Tx[i]; //print(x); for (int i = 1; i <= N; ++i) { P.push_back(i); use[i] = 1; if (recon(1, P)) { vector<int> ans(N); for (i = 0; i < N; ++i) ans[V[i] - 1] = P[i];// , printf("%d,%d\n", V[i], P[i]); answer(ans); break; } P.pop_back(); use[i] = 0; } }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 256 KB | Output is correct |
2 | Correct | 4 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 | 384 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 256 KB | Output is correct |
2 | Correct | 4 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 | 384 KB | Output is correct |
7 | Correct | 5 ms | 384 KB | Output is correct |
8 | Correct | 5 ms | 256 KB | Output is correct |
9 | Correct | 5 ms | 384 KB | Output is correct |
10 | Correct | 5 ms | 256 KB | Output is correct |
11 | Correct | 5 ms | 256 KB | Output is correct |
12 | Correct | 5 ms | 384 KB | Output is correct |
13 | Correct | 5 ms | 256 KB | Output is correct |
14 | Correct | 5 ms | 384 KB | Output is correct |
15 | Correct | 5 ms | 256 KB | Output is correct |
16 | Correct | 5 ms | 384 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 256 KB | Output is correct |
2 | Correct | 4 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 | 384 KB | Output is correct |
7 | Correct | 5 ms | 384 KB | Output is correct |
8 | Correct | 5 ms | 256 KB | Output is correct |
9 | Correct | 5 ms | 384 KB | Output is correct |
10 | Correct | 5 ms | 256 KB | Output is correct |
11 | Correct | 5 ms | 256 KB | Output is correct |
12 | Correct | 5 ms | 384 KB | Output is correct |
13 | Correct | 5 ms | 256 KB | Output is correct |
14 | Correct | 5 ms | 384 KB | Output is correct |
15 | Correct | 5 ms | 256 KB | Output is correct |
16 | Correct | 5 ms | 384 KB | Output is correct |
17 | Correct | 29 ms | 432 KB | Output is correct |
18 | Execution timed out | 5049 ms | 256 KB | Time limit exceeded |
19 | Halted | 0 ms | 0 KB | - |