#include "park.h"
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ii pair<ll,ll>
#define fi first
#define se second
#define endl '\n'
#define puf push_front
#define pof pop_front
#define pub push_back
#define pob pop_back
#define lb lower_bound
#define ub upper_bound
#define rep(x,s,e) for (auto x=s-(s>e);x!=e-(s>e);s<e?x++:x--)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int) (x).size()
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int t,n;
int Ask(int i,int j,vector<int> v){
//cout<<"Ask: "<<i<<" "<<j<<" | "; for (auto &it:v) cout<<it<<" "; cout<<endl;
if (i>j) swap(i,j); //the fuck?
int arr[n];
memset(arr,0,sizeof(arr));
for (auto &it:v) arr[it]^=1;
return Ask(i,j,arr);
}
void ans(int i,int j){
if (i>j) swap(i,j);
Answer(i,j);
}
void rec(vector<int> v){
//cout<<"debug: "; for (auto &it:v) cout<<it<<" "; cout<<endl;
if (sz(v)==1) return;
//try to make pivot the centroid
shuffle(all(v),rng);
int root=v[sz(v)-1];
//high chance this is a descendant of the centroid
int pivot=v[sz(v)-2];
//we can try to find parents of the current pivot?
vector<int> par;
for (auto &it:v){
if (it==root) continue;
if (it==pivot){
par.pub(it);
continue;
}
vector<int> vv=v;
vv.pub(it);
if (Ask(root,pivot,vv)==0) par.pub(it);
}
while (sz(par)!=1){
int temp=par[rng()%sz(par)];
set<int> spar;
for (auto &it:par) spar.insert(it);
vector<int> lower,upper;
int subsize=0;
for (auto &it:v){
if (it==root) continue;
if (it==temp) continue;
vector<int> vv=v;
vv.pub(temp);
if (Ask(root,it,vv)==0){
subsize++;
if (spar.count(it)) lower.pub(it);
}
else{
if (spar.count(it)) upper.pub(it);
}
}
if (subsize>sz(v)/2){
par=lower;
if (par.empty()) par.pub(temp);
}
else{
par=upper;
if (par.empty()) par.pub(root);
}
}
pivot=par[0];
rep(x,0,sz(v)) if (v[x]==pivot) swap(v[x],v.back());
v.pob();
while (sz(v)){
vector<int> split;
vector<int> rest;
split.pub(v.back());
for (auto &it:v){
if (it==split[0]) continue;
if (Ask(split[0],it,v)==1) split.pub(it);
else rest.pub(it);
}
//now we need to find how split is connected to pivot
vector<int> cset={pivot};
int connect;
for (auto &it:split){
cset.pub(it);
if (Ask(it,pivot,cset)){
ans(it,pivot);
connect=it;
break;
}
}
rec(split);
v=rest;
}
}
void Detect(int T, int N) {
t=T,n=N;
if (t==1){
rep(x,0,n) rep(y,x+1,n){
if (Ask(x,y,{x,y})==1) Answer(x,y);
}
}
else{
vector<int> proc;
rep(x,0,n) proc.pub(x);
rec(proc);
}
}
Compilation message
park.cpp: In function 'void rec(std::vector<int>)':
park.cpp:125:7: warning: variable 'connect' set but not used [-Wunused-but-set-variable]
125 | int connect;
| ^~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
8 ms |
328 KB |
Output is correct |
3 |
Correct |
7 ms |
332 KB |
Output is correct |
4 |
Correct |
8 ms |
332 KB |
Output is correct |
5 |
Correct |
8 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
408 ms |
724 KB |
Wrong Answer[5] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
463 ms |
580 KB |
Wrong Answer[5] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
230 ms |
452 KB |
Wrong Answer[5] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1323 ms |
836 KB |
Wrong Answer[5] |
2 |
Halted |
0 ms |
0 KB |
- |