#include "park.h"
#include <bits/stdc++.h>
using namespace std;
bool in[1400];
static int place[1400];
vector<int> post;
vector<int> adj[1400];
vector<bool> v;
int n;
void dfs(int now){
v[now] = true;
post.push_back(now);
for(int i = 0; i<adj[now].size(); i++){
int to = adj[now][i];
if(!v[to]){
dfs(to);
}
}
}
void from(int a, int b){
if(b<a){
swap(a,b);
}
// cout << "FROM " << a << " " << b << endl;
for(int i = 0; i<n; i++){
place[i] = 0;
}
place[a] = 1;
place[b] = 1;
// cout << "P1 " << a << " " << b << endl;
// for(int i = 0; i<n; i++){
// cout << place[i] << " " ;
// }
// cout << endl;
if(Ask(a,b,place)==1){
// cout << "OK " << endl;
Answer(a,b);
in[a] = true;
in[b] = true;
adj[a].push_back(b);
adj[b].push_back(a);
return;
}
// cout << "NOPE " << endl;
vector<int> outside;
for(int i = 0; i<n; i++){
if(!in[i] && i!=a && i!=b){
outside.push_back(i);
}
}
int low = 0;
int high = (int)outside.size()-1;
while(low<high){
int mid = (low+high)/2;
for(int i = 0; i<n; i++){
place[i] = 1;
}
for(int i = 0; i<=mid; i++){
place[outside[i]] = 1;
}
for(int i = mid+1; i<(int)outside.size(); i++){
place[outside[i]] = 0;
}
if(Ask(a,b,place)==1){
high = mid;
}
else{
low = mid+1;
}
}
from(a,outside[low]);
from(outside[low],b);
}
void Detect(int T, int N) {
if(T==5){
return;
}
n = N;
for(int i = 0; i<N; i++){
place[i] = 0;
}
for(int i = 0; i<N; i++){
in[i] = false;
}
in[0] = true;
for(int i = 1; i<N; i++){
// cout << "X " << i << " " << N << endl;
if(in[i]){
continue;
}
v.clear();
v.resize(N);
post.clear();
dfs(0);
vector<int> possible;
for(int j = 0; j<post.size(); j++){
possible.push_back(post[j]);
}
// cout << "A " << endl;
// for(int j = 0; j<(int)possible.size(); j++){
// cout << possible[j] << " " ;
// }
// cout << "B "<< endl;
while(possible.size()>1){
vector<int> a;
vector<int> b;
for(int j = 0; j<N; j++){
place[j] = 1;
}
for(int j = 0; j<(int)possible.size()/2; j++){
a.push_back(possible[j]);
}
for(int j = (int)possible.size()/2; j<(int)possible.size(); j++){
b.push_back(possible[j]);
place[possible[j]] = 0;
}
// cout << "BEF " << endl;
// for(int j = 0; j<a.size(); j++){
// cout << a[j] << " ";
// }
// cout << endl;
// for(int j = 0; j<b.size(); j++){
// cout << b[j] << " ";
// }
// cout << endl;
// for(int j = 0; j<N; j++){
// cout << place[j] << " ";
// }
// cout << endl;
int xx = a[0];
int yy = i;
if(xx>yy){
swap(xx,yy);
}
if(Ask(xx,yy,place)==1){
possible = a;
}
else{
possible = b;
}
// cout << "AFT " << endl;
}
assert((int)possible.size()==1);
from(possible[0],i);
}
}
Compilation message
park.cpp: In function 'void dfs(int)':
park.cpp:14:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 0; i<adj[now].size(); i++){
~^~~~~~~~~~~~~~~~
park.cpp: In function 'void Detect(int, int)':
park.cpp:97:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int j = 0; j<post.size(); j++){
~^~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
11 ms |
2040 KB |
Wrong Answer[5] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
80 ms |
2040 KB |
Output is correct |
2 |
Correct |
156 ms |
2040 KB |
Output is correct |
3 |
Correct |
124 ms |
2764 KB |
Output is correct |
4 |
Correct |
73 ms |
2764 KB |
Output is correct |
5 |
Correct |
74 ms |
2764 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
195 ms |
2764 KB |
Output is correct |
2 |
Correct |
210 ms |
2764 KB |
Output is correct |
3 |
Correct |
216 ms |
2764 KB |
Output is correct |
4 |
Correct |
239 ms |
2764 KB |
Output is correct |
5 |
Correct |
225 ms |
2764 KB |
Output is correct |
6 |
Correct |
206 ms |
2764 KB |
Output is correct |
7 |
Correct |
199 ms |
2764 KB |
Output is correct |
8 |
Correct |
210 ms |
2764 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
101 ms |
2764 KB |
Output is correct |
2 |
Correct |
225 ms |
2764 KB |
Output is correct |
3 |
Correct |
221 ms |
2764 KB |
Output is correct |
4 |
Correct |
171 ms |
2764 KB |
Output is correct |
5 |
Correct |
182 ms |
2764 KB |
Output is correct |
6 |
Correct |
128 ms |
2764 KB |
Output is correct |
7 |
Correct |
129 ms |
2764 KB |
Output is correct |
8 |
Correct |
190 ms |
2764 KB |
Output is correct |
9 |
Correct |
177 ms |
2764 KB |
Output is correct |
10 |
Correct |
166 ms |
2764 KB |
Output is correct |
11 |
Correct |
180 ms |
2764 KB |
Output is correct |
12 |
Correct |
226 ms |
2764 KB |
Output is correct |
13 |
Correct |
128 ms |
2764 KB |
Output is correct |
14 |
Correct |
190 ms |
2764 KB |
Output is correct |
15 |
Correct |
128 ms |
2764 KB |
Output is correct |
16 |
Correct |
214 ms |
2764 KB |
Output is correct |
17 |
Correct |
68 ms |
2764 KB |
Output is correct |
18 |
Correct |
177 ms |
2764 KB |
Output is correct |
19 |
Correct |
114 ms |
2764 KB |
Output is correct |
20 |
Correct |
190 ms |
2764 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
2764 KB |
Wrong Answer[6] |
2 |
Halted |
0 ms |
0 KB |
- |