#include "park.h"
#include <bits/stdc++.h>
using namespace std;
#define a first
#define b second
#define pb push_back
typedef long long llo;
#define endl '\n'
int query(int x,int y,int Place[]){
return Ask(min(x,y),max(x,y),Place);
}
static int cur[1501];
vector<int> adj[1501];
int vis[1501];
int par3[1501];
vector<int> ss;
void dfs(int no,int par=-1){
ss.pb(no);
for(auto j:adj[no]){
if(j!=par){
dfs(j,no);
}
}
}
int n;
vector<int> kk;
int xa;
bool cmp(int aa,int bb){
if(aa==bb){
return false;
}
for(int i=0;i<n;i++){
cur[i]=0;
}
for(auto j:kk){
cur[j]=1;
}
cur[xa]=1;
cur[aa]=0;
if(query(min(xa,bb),max(xa,bb),cur)==1){
return false;
}
else{
return true;
}
}
int val[1501];
vector<int> ee;
void dfs3(int no,int par=-1){
ee.pb(no);
for(auto j:adj[no]){
if(j!=par and val[j]==1){
dfs3(j,no);
}
}
}
vector<pair<int,int>> ans;
void solve(int i,vector<int> tt){
if(tt.size()==0){
return;
}
/* cout<<i<<":";
for(auto j:tt){
cout<<j<<",";
}
cout<<endl;*/
for(int j=0;j<n;j++){
val[j]=0;
}
for(auto j:tt){
val[j]=1;
}
assert(val[i]==0);
ee.clear();
dfs3(tt[0]);
for(int j=0;j<n;j++){
cur[j]=0;
}
for(auto j:ee){
cur[j]=1;
}
cur[i]=1;
if(query(i,ee[0],cur)==1){
//cout<<11<<endl;
int low=-1;
for(int j=19;j>=0;j--){
if(low+(1<<j)<ee.size()){
for(int ii=0;ii<ee.size();ii++){
if(ii<=(low+(1<<j))){
cur[ee[ii]]=1;
}
else{
cur[ee[ii]]=0;
}
}
if(query(i,ee[0],cur)==0){
low+=(1<<j);
}
}
}
low++;
int x=ee[low];
//cout<<x<<",,,,,"<<i<<endl;
ans.pb({x,i});
vector<int> mm;
for(auto j:adj[x]){
if(val[j]==1){
mm.pb(j);
}
}
val[x]=0;
vector<vector<int>> za;
for(auto j:mm){
ee.clear();
dfs3(j);
za.pb(ee);
}
for(auto j:za){
solve(i,j);
}
}
else{
return;
}
}
void Detect(int t, int nn) {
int i;
n=nn;
/*if(t==1){
for(int i=0;i<n;i++){
for(int j=i+1;j<n;j++){
for(int x=0;x<n;x++){
cur[x]=0;
}
cur[i]=1;
cur[j]=1;
if(query(i,j,cur)==1){
Answer(i,j);
}
}
}
return;
}*/
vis[0]=1;
for(int i=1;i<n;i++){
if(vis[i]==0){
ss.clear();
dfs(0);
for(int j=0;j<n;j++){
cur[j]=1;
}
int low=-1;
for(int j=19;j>=0;j--){
if(low+(1<<j)<ss.size()){
for(int ii=0;ii<ss.size();ii++){
if(ii<=(low+(1<<j))){
cur[ss[ii]]=1;
}
else{
cur[ss[ii]]=0;
}
}
/* if(i==2 and low+(1<<j)==0){
for(int jj=0;jj<n;jj++){
cout<<cur[jj]<<",,";
}
cout<<endl;
cout<<query(0,i,cur)<<endl;
}*/
if(query(0,i,cur)==0){
low+=(1<<j);
}
}
}
low++;
int x=ss[low];
/* for(auto j:ss){
cout<<j<<"::";
}
cout<<low<<"?"<<endl;
cout<<endl;
*/
vector<int> tt;
vis[i]=1;
for(int j=0;j<n;j++){
if(vis[j]==0){
tt.pb(j);
}
}
for(int j=0;j<n;j++){
cur[j]=0;
}
for(int j=0;j<=low;j++){
cur[ss[j]]=1;
}
cur[i]=1;
low=-1;
// cout<<22<<endl;
kk.clear();
while(true){
for(int j=19;j>=0;j--){
if(low+(1<<j)<tt.size()){
for(int ii=0;ii<tt.size();ii++){
if(ii<=(low+(1<<j))){
cur[tt[ii]]=0;
}
else{
cur[tt[ii]]=1;
}
}
for(auto ii:kk){
cur[ii]=1;
}
/* cout<<33<<endl;
for(int jj=0;jj<n;jj++){
cout<<cur[jj]<<":";
}
cout<<endl;*/
if(query(0,i,cur)==1){
low+=(1<<j);
}
}
}
//from prev to low nothing is there
//low+1 is there
if(low+1==tt.size()){
break;
}
low++;
kk.pb(tt[low]);
//low+1 must be there
}
// cout<<44<<endl;
//you need to sort elements of kk between x and i
for(auto j:kk){
vis[j]=1;
}
xa=x;
sort(kk.begin(),kk.end(),cmp);
kk.pb(i);
/* cout<<x<<",";
for(auto j:kk){
cout<<j<<",";
}
cout<<endl;*/
for(auto j:kk){
adj[x].pb(j);
par3[j]=x;
adj[j].pb(x);
x=j;
}
}
}
for(int i=1;i<n;i++){
//cout<<i<<":"<<par3[i]<<endl;
for(auto j:adj[par3[i]]){
if(j==i){
continue;
}
if(j!=par3[par3[i]]){
if(j<i){
continue;
}
}
ss.clear();
dfs(j,par3[i]);
solve(i,ss);
}
}
for(int i=0;i<n;i++){
for(auto j:adj[i]){
if(i>j){
continue;
}
//cout<<i<<":"<<j<<endl;
Answer(min(i,j),max(i,j));
}
}
set<pair<int,int>> cot;
for(auto j:ans){
cot.insert({min(j.a,j.b),max(j.a,j.b)});
}
for(auto j:cot){
//cout<<j.a<<"::"<<j.b<<endl;
Answer(min(j.a,j.b),max(j.a,j.b));
}
}
Compilation message
park.cpp: In function 'void solve(int, std::vector<int>)':
park.cpp:90:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
90 | if(low+(1<<j)<ee.size()){
| ~~~~~~~~~~^~~~~~~~~~
park.cpp:91:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
91 | for(int ii=0;ii<ee.size();ii++){
| ~~^~~~~~~~~~
park.cpp: In function 'void Detect(int, int)':
park.cpp:163:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
163 | if(low+(1<<j)<ss.size()){
| ~~~~~~~~~~^~~~~~~~~~
park.cpp:164:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
164 | for(int ii=0;ii<ss.size();ii++){
| ~~^~~~~~~~~~
park.cpp:217:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
217 | if(low+(1<<j)<tt.size()){
| ~~~~~~~~~~^~~~~~~~~~
park.cpp:218:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
218 | for(int ii=0;ii<tt.size();ii++){
| ~~^~~~~~~~~~
park.cpp:241:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
241 | if(low+1==tt.size()){
| ~~~~~^~~~~~~~~~~
park.cpp:136:6: warning: unused variable 'i' [-Wunused-variable]
136 | int i;
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
6 ms |
468 KB |
Output is correct |
3 |
Correct |
5 ms |
468 KB |
Output is correct |
4 |
Correct |
19 ms |
468 KB |
Output is correct |
5 |
Correct |
45 ms |
552 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
118 ms |
504 KB |
Output is correct |
2 |
Correct |
114 ms |
592 KB |
Output is correct |
3 |
Correct |
105 ms |
616 KB |
Output is correct |
4 |
Correct |
135 ms |
520 KB |
Output is correct |
5 |
Correct |
140 ms |
608 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
139 ms |
472 KB |
Output is correct |
2 |
Correct |
142 ms |
468 KB |
Output is correct |
3 |
Correct |
145 ms |
472 KB |
Output is correct |
4 |
Correct |
134 ms |
468 KB |
Output is correct |
5 |
Correct |
146 ms |
468 KB |
Output is correct |
6 |
Correct |
135 ms |
468 KB |
Output is correct |
7 |
Correct |
132 ms |
460 KB |
Output is correct |
8 |
Correct |
142 ms |
480 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
65 ms |
456 KB |
Output is correct |
2 |
Correct |
150 ms |
508 KB |
Output is correct |
3 |
Correct |
150 ms |
480 KB |
Output is correct |
4 |
Correct |
122 ms |
476 KB |
Output is correct |
5 |
Correct |
166 ms |
588 KB |
Output is correct |
6 |
Correct |
141 ms |
584 KB |
Output is correct |
7 |
Correct |
112 ms |
488 KB |
Output is correct |
8 |
Correct |
136 ms |
468 KB |
Output is correct |
9 |
Correct |
125 ms |
480 KB |
Output is correct |
10 |
Correct |
160 ms |
496 KB |
Output is correct |
11 |
Correct |
151 ms |
488 KB |
Output is correct |
12 |
Correct |
143 ms |
472 KB |
Output is correct |
13 |
Correct |
116 ms |
492 KB |
Output is correct |
14 |
Correct |
149 ms |
536 KB |
Output is correct |
15 |
Correct |
118 ms |
516 KB |
Output is correct |
16 |
Correct |
147 ms |
468 KB |
Output is correct |
17 |
Correct |
163 ms |
512 KB |
Output is correct |
18 |
Correct |
139 ms |
488 KB |
Output is correct |
19 |
Correct |
130 ms |
496 KB |
Output is correct |
20 |
Correct |
138 ms |
468 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
225 ms |
616 KB |
Output is correct |
2 |
Correct |
205 ms |
588 KB |
Output is correct |
3 |
Correct |
167 ms |
552 KB |
Output is correct |
4 |
Correct |
159 ms |
512 KB |
Output is correct |
5 |
Correct |
218 ms |
620 KB |
Output is correct |
6 |
Correct |
139 ms |
588 KB |
Output is correct |
7 |
Correct |
174 ms |
628 KB |
Output is correct |
8 |
Correct |
157 ms |
644 KB |
Output is correct |
9 |
Correct |
153 ms |
516 KB |
Output is correct |
10 |
Correct |
165 ms |
496 KB |
Output is correct |
11 |
Correct |
139 ms |
508 KB |
Output is correct |
12 |
Correct |
153 ms |
520 KB |
Output is correct |
13 |
Correct |
164 ms |
488 KB |
Output is correct |
14 |
Correct |
207 ms |
576 KB |
Output is correct |
15 |
Correct |
159 ms |
512 KB |
Output is correct |
16 |
Correct |
146 ms |
484 KB |
Output is correct |
17 |
Correct |
161 ms |
528 KB |
Output is correct |
18 |
Correct |
161 ms |
628 KB |
Output is correct |