# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1054541 | 2024-08-12T10:34:18 Z | bachhoangxuan | Secret Permutation (RMI19_permutation) | C++17 | 1860 ms | 600 KB |
#include "permutation.h" #include<bits/stdc++.h> using namespace std; void solve(int n){ vector<int> D(n),P(n); iota(P.begin(),P.end(),1); shuffle(P.begin(),P.end(),mt19937(1)); int S=0; for(int i=0;i<n;i++) S+=(D[i]=query(P)),rotate(P.begin(),P.begin()+1,P.end()); S/=(n-1); for(int &x:D) x=S-x; vector<int> a(n),vis(n+1); function<void(int)> dfs = [&](int i){ if(i>=n){ if(abs(a[0]-a[n-1])!=D[0]) return; vector<int> res(n); for(int i=0;i<n;i++) res[P[i]-1]=a[i]; answer(res); return; } for(int t:{-1,1}){ int x=a[i-1]+t*D[i]; if(1<=x && x<=n && !vis[x]){ a[i]=x,vis[x]=1; dfs(i+1); vis[x]=0; } } }; for(int i=1;i<=n;i++){ a[0]=i,vis[i]=1; dfs(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 | 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 | 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 | 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 | 1 ms | 344 KB | Output is correct |
14 | Correct | 0 ms | 440 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 | 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 | 1 ms | 344 KB | Output is correct |
10 | Correct | 1 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 | 1 ms | 344 KB | Output is correct |
14 | Correct | 0 ms | 440 KB | Output is correct |
15 | Correct | 1 ms | 344 KB | Output is correct |
16 | Correct | 0 ms | 344 KB | Output is correct |
17 | Correct | 5 ms | 440 KB | Output is correct |
18 | Correct | 89 ms | 344 KB | Output is correct |
19 | Correct | 607 ms | 344 KB | Output is correct |
20 | Correct | 29 ms | 444 KB | Output is correct |
21 | Correct | 4 ms | 344 KB | Output is correct |
22 | Correct | 5 ms | 344 KB | Output is correct |
23 | Correct | 7 ms | 344 KB | Output is correct |
24 | Correct | 1617 ms | 600 KB | Output is correct |
25 | Correct | 71 ms | 596 KB | Output is correct |
26 | Correct | 1860 ms | 444 KB | Output is correct |