# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1054408 | 2024-08-12T09:40:48 Z | vjudge1 | Secret Permutation (RMI19_permutation) | C++14 | 1635 ms | 448 KB |
#include "permutation.h" #include <bits/stdc++.h> using namespace std; void solve(int n) { vector<int> v(n); iota(v.begin(), v.end(), 1); shuffle(v.begin(), v.end(), mt19937(1)); vector<int> d1(n); for (int i=0; i<n; ++i){ d1[i]=query(v); rotate(v.begin(), v.begin()+1, v.end()); } int sum=accumulate(d1.begin(), d1.end(), 0)/(n-1); for (int &i:d1) i=sum-i; vector<int> ans(n); vector<int> vis(n+1); auto backtrack=[&](auto &&self, int i){ if (i>=n){ if (abs(ans[n-1]-ans[0])!=d1[0]) return; vector<int> res(n); for (int i=0; i<n; ++i) res[v[i]-1]=ans[i]; answer(res); } int x=ans[i-1]+d1[i]; if (1<=x && x<=n && !vis[x]){ vis[x]=1; ans[i]=x; self(self, i+1); vis[x]=0; } x=ans[i-1]-d1[i]; if (1<=x && x<=n && !vis[x]){ vis[x]=1; ans[i]=x; self(self, i+1); vis[x]=0; } }; for (int i=1; i<=n; ++i){ vis[i]=1; ans[0]=i; backtrack(backtrack, 1); vis[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 | 376 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 | 376 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 | 1 ms | 344 KB | Output is correct |
10 | Correct | 1 ms | 440 KB | Output is correct |
11 | Correct | 1 ms | 344 KB | Output is correct |
12 | Correct | 1 ms | 340 KB | Output is correct |
13 | Correct | 1 ms | 344 KB | Output is correct |
14 | Correct | 0 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 | 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 | 376 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 | 1 ms | 344 KB | Output is correct |
10 | Correct | 1 ms | 440 KB | Output is correct |
11 | Correct | 1 ms | 344 KB | Output is correct |
12 | Correct | 1 ms | 340 KB | Output is correct |
13 | Correct | 1 ms | 344 KB | Output is correct |
14 | Correct | 0 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 | 6 ms | 344 KB | Output is correct |
18 | Correct | 58 ms | 444 KB | Output is correct |
19 | Correct | 501 ms | 440 KB | Output is correct |
20 | Correct | 24 ms | 344 KB | Output is correct |
21 | Correct | 4 ms | 344 KB | Output is correct |
22 | Correct | 7 ms | 440 KB | Output is correct |
23 | Correct | 7 ms | 344 KB | Output is correct |
24 | Correct | 1370 ms | 440 KB | Output is correct |
25 | Correct | 55 ms | 448 KB | Output is correct |
26 | Correct | 1635 ms | 344 KB | Output is correct |