# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
217826 | 2fat2code | Secret Permutation (RMI19_permutation) | C++17 | 670 ms | 512 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "permutation.h"
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define all(a) (a).begin(), (a).end()
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define sz() size()
#define fr first
#define sc second
#define pi pair<int,int>
#define pii pair<pair<int,int>,int>
#define mp make_pair
//#define int long long
#define rc(s) return cout<<s,0
#define rcc(s) cout<<s,exit(0)
using namespace std;
const int mod=1e9+7;
const int modp=1999999973;
const int modulo=998244353;
int n;
bitset<257>viz;
vector<int>v,arr(257),ans(257),fin(257);
vector<int>answ;
void DFS(int curr){
viz[ans[curr]]=1;
if(curr==n && abs(ans[curr]-ans[1])==arr[n]){
for(int i=1;i<=n;i++){
fin[v[i-1]]=ans[i];
}
for(int i=1;i<=n;i++){
answ.push_back(fin[i]);
}
answer(answ);
exit(0);
}
else{
int x1=(ans[curr] - arr[curr]);
int x2=(ans[curr] + arr[curr]);
if(x1>=1 && x1<=n && viz[x1]==0 && abs(x1-ans[curr])==arr[curr]){
ans[curr+1]=(x1);
DFS(curr+1);
}
if(x2>=1 && x2<=n && viz[x2]==0 && abs(x2-ans[curr])==arr[curr]){
ans[curr+1]=(x2);
DFS(curr+1);
}
}
viz[ans[curr]]=0;
ans[curr]=0;
}
void solve(int N){
ios_base::sync_with_stdio(false);cin.tie(0);cerr.tie(0);cout.tie(0);
srand(chrono::steady_clock::now().time_since_epoch().count());
n=N;
for(int i=1;i<=n;i++){
v.push_back(i);
}
random_shuffle(all(v));
for(int i=1;i<=n;i++){
rotate(v.begin(),v.begin()+1,v.end());
arr[i] = query(v);
}
rotate(v.begin(),v.begin()+1,v.end());
int sum=0;
for(int i=1;i<=n;i++){
sum+=arr[i];
}
sum/=(n-1);
for(int i=1;i<=n;i++) arr[i]=(sum-arr[i]);
arr[n+1]=arr[1];
for(int i=1;i<=n;i++) arr[i]=arr[i+1];
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++) ans[j]=0;
ans[1]=i;
viz.reset();
DFS(1);
}
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |