# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1054221 | 2024-08-12T07:44:17 Z | socpite | Secret Permutation (RMI19_permutation) | C++17 | 5000 ms | 344 KB |
#include "permutation.h" #include<bits/stdc++.h> using namespace std; const int maxn = 300; namespace { int n; long long D[maxn]; bool vis[maxn]; vector<int> crr; vector<vector<int>> allans; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); int prv(int x){ return x == 0 ? n-1 : x-1; } int nxt(int x){ return x == n-1 ? 0 : x+1; } } void bt(int l, int r){ if(nxt(r) == l){ if(abs(crr[l] - crr[r]) != D[l])return; allans.push_back(crr); return; } int pr = nxt(r); int op1 = crr[r] + D[pr], op2 = crr[r] - D[pr]; if(op1 > n || vis[op1]){ if(op2 < 1 || vis[op2])return; vis[op2] = 1; crr[pr] = op2; bt(l, pr); vis[op2] = 0; } else if(op2 < 1 || vis[op2]){ vis[op1] = 1; crr[pr] = op1; bt(l, pr); vis[op1] = 0; } else { int pl = prv(l); op1 = crr[l] + D[l], op2 = crr[l] - D[l]; if(op1 <= n && !vis[op1]){ crr[pl] = op1; vis[op1] = 1; bt(pl, r); vis[op1] = 0; } if(op2 >= 1 && !vis[op2]){ crr[pl] = op2; vis[op2] = 1; bt(pl, r); vis[op2] = 0; } } } void solve(int N) { n = N; long long sum = 0; vector<int> P(N); crr.resize(N, 0); iota(P.begin(), P.end(), 1); // shuffle(P.begin(), P.end(), rng); for(int i = 0; i < N; i++){ D[i] = query(P); sum += D[i]; P.push_back(P[0]); P.erase(P.begin()); } sum /= N-1; for(int i = 0; i < N; i++){ D[i] = sum - D[i]; // cout << D[i] << endl; } allans.clear(); for(int i = 1; i <= N; i++){ crr[0] = i; vis[i] = 1; bt(0, 0); vis[i] = 0; } while(allans.size() > 2){ shuffle(P.begin(), P.end(), rng); vector<vector<int>> nw; int chksum = query(P); for(auto vec: allans){ int csum = 0; for(int i = 1; i < N; i++)csum += abs(vec[P[i]-1] - vec[P[i-1]-1]); if(csum == chksum)nw.push_back(vec); } allans = nw; } answer(allans.back()); }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 344 KB | Output is correct |
2 | Partially correct | 0 ms | 344 KB | Partially 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 | Partially correct | 0 ms | 344 KB | Partially 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 | 344 KB | Output is correct |
8 | Correct | 0 ms | 344 KB | Output is correct |
9 | Correct | 0 ms | 344 KB | Output is correct |
10 | Correct | 0 ms | 344 KB | Output is correct |
11 | Correct | 0 ms | 344 KB | Output is correct |
12 | Correct | 1 ms | 344 KB | Output is correct |
13 | Correct | 0 ms | 344 KB | Output is correct |
14 | Correct | 1 ms | 344 KB | Output is correct |
15 | Correct | 1 ms | 344 KB | Output is correct |
16 | Correct | 0 ms | 344 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 344 KB | Output is correct |
2 | Partially correct | 0 ms | 344 KB | Partially 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 | 344 KB | Output is correct |
8 | Correct | 0 ms | 344 KB | Output is correct |
9 | Correct | 0 ms | 344 KB | Output is correct |
10 | Correct | 0 ms | 344 KB | Output is correct |
11 | Correct | 0 ms | 344 KB | Output is correct |
12 | Correct | 1 ms | 344 KB | Output is correct |
13 | Correct | 0 ms | 344 KB | Output is correct |
14 | Correct | 1 ms | 344 KB | Output is correct |
15 | Correct | 1 ms | 344 KB | Output is correct |
16 | Correct | 0 ms | 344 KB | Output is correct |
17 | Correct | 173 ms | 344 KB | Output is correct |
18 | Correct | 26 ms | 344 KB | Output is correct |
19 | Execution timed out | 5062 ms | 344 KB | Time limit exceeded |
20 | Halted | 0 ms | 0 KB | - |