# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
259607 | 2020-08-08T04:08:29 Z | dvdg6566 | Secret Permutation (RMI19_permutation) | C++14 | 4 ms | 256 KB |
#include "permutation.h" #include<bits/stdc++.h> using namespace std; typedef vector<int> vi; const int MAXN = 256; #define pb push_back #define SZ(x) (int)x.size() int firsts[MAXN]; int mids[MAXN]; int K; int find_diff(int pivot,int a,int b){ vi V; V.pb(a);V.pb(b);V.pb(pivot); for(int i=1;i<=K;++i){ if(i!=a&&i!=b&&i!=pivot)V.pb(i); } int k=query(V); V.clear(); V.pb(b);V.pb(a);V.pb(pivot); for(int i=1;i<=K;++i){ if(i!=a&&i!=b&&i!=pivot)V.pb(i); } int p=query(V); return k-p; } void solve(int N) { K=N; for(int i=1;i+2<=N;++i){ firsts[i]=find_diff(i,i+1,i+2); // cerr<<"F "<<i<<' '<<firsts[i]<<'\n'; } for(int i=2;i+1<=N;++i){ mids[i]=find_diff(i,i-1,i+1); // cerr<<"M "<<i<<' '<<mids[i]<<'\n'; } vi ans; for(int i=1;i<=N;++i)for(int j=1;j<=N;++j){ if(i==j)continue; ans.clear(); ans.pb(i); ans.pb(j); bool fail=0; while(SZ(ans)<N){ // cerr<<"Length "<<SZ(ans)<<'\n'; int lastdif=abs(ans[SZ(ans)-1] - ans[SZ(ans)-2]); // cerr<<lastdif<<'\n'; int otdiff=abs(firsts[SZ(ans)-1]+lastdif); // cout<<otdiff<<'\n'; int stdiff=abs(mids[SZ(ans)]+lastdif); // cout<<stdiff<<'\n'; int a=ans[SZ(ans)-2]; int b=ans[SZ(ans)-1]; if(otdiff == stdiff+lastdif){ if(a>b)ans.pb(a-otdiff); else ans.pb(a+otdiff); }else if(stdiff == otdiff+lastdif){ // closer to first one if(a>b)ans.pb(a+otdiff); else ans.pb(a-otdiff); }else if(otdiff + stdiff == lastdif){ if(a>b)ans.pb(a-otdiff); else ans.pb(a+otdiff); }else{ fail=1;break; } } for(auto i:ans)if(i>N||i<1)fail=1; // cerr<<fail<<'\n'; if(fail==0){answer(ans);return;} } answer(ans); }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Partially correct | 1 ms | 256 KB | Partially correct |
2 | Partially correct | 0 ms | 256 KB | Partially correct |
3 | Partially correct | 0 ms | 256 KB | Partially correct |
4 | Partially correct | 1 ms | 256 KB | Partially correct |
5 | Partially correct | 1 ms | 256 KB | Partially correct |
6 | Partially correct | 0 ms | 256 KB | Partially correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Partially correct | 1 ms | 256 KB | Partially correct |
2 | Partially correct | 0 ms | 256 KB | Partially correct |
3 | Partially correct | 0 ms | 256 KB | Partially correct |
4 | Partially correct | 1 ms | 256 KB | Partially correct |
5 | Partially correct | 1 ms | 256 KB | Partially correct |
6 | Partially correct | 0 ms | 256 KB | Partially correct |
7 | Partially correct | 4 ms | 256 KB | Partially correct |
8 | Incorrect | 4 ms | 256 KB | Output isn't correct |
9 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Partially correct | 1 ms | 256 KB | Partially correct |
2 | Partially correct | 0 ms | 256 KB | Partially correct |
3 | Partially correct | 0 ms | 256 KB | Partially correct |
4 | Partially correct | 1 ms | 256 KB | Partially correct |
5 | Partially correct | 1 ms | 256 KB | Partially correct |
6 | Partially correct | 0 ms | 256 KB | Partially correct |
7 | Partially correct | 4 ms | 256 KB | Partially correct |
8 | Incorrect | 4 ms | 256 KB | Output isn't correct |
9 | Halted | 0 ms | 0 KB | - |