#define DEBUG 0
#include <bits/stdc++.h>
using namespace std;
#if DEBUG
// basic debugging macros
int __i__,__j__;
#define printLine(l) for(__i__=0;__i__<l;__i__++){cout<<"-";}cout<<endl
#define printLine2(l,c) for(__i__=0;__i__<l;__i__++){cout<<c;}cout<<endl
#define printVar(n) cout<<#n<<": "<<n<<endl
#define printArr(a,l) cout<<#a<<": ";for(__i__=0;__i__<l;__i__++){cout<<a[__i__]<<" ";}cout<<endl
#define print2dArr(a,r,c) cout<<#a<<":\n";for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<a[__i__][__j__]<<" ";}cout<<endl;}
#define print2dArr2(a,r,c,l) cout<<#a<<":\n";for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<setw(l)<<setfill(' ')<<a[__i__][__j__]<<" ";}cout<<endl;}
// advanced debugging class
// debug 1,2,'A',"test";
class _Debug {
public:
template<typename T>
_Debug& operator,(T val) {
cout << val << endl;
return *this;
}
};
#define debug _Debug(),
#else
#define printLine(l)
#define printLine2(l,c)
#define printVar(n)
#define printArr(a,l)
#define print2dArr(a,r,c)
#define print2dArr2(a,r,c,l)
#define debug
#endif
// define
#define MAX_VAL 999999999
#define MAX_VAL_2 999999999999999999LL
#define EPS 1e-6
#define mp make_pair
#define pb push_back
// typedef
typedef unsigned int UI;
typedef long long int LLI;
typedef unsigned long long int ULLI;
typedef unsigned short int US;
typedef pair<int,int> pii;
typedef pair<LLI,LLI> plli;
typedef vector<int> vi;
typedef vector<LLI> vlli;
typedef vector<pii> vpii;
typedef vector<plli> vplli;
// ---------- END OF TEMPLATE ----------
#include "park.h"
int P[1400];
int ask(int A,int B,int *P) {
if (A > B) swap(A,B);
return Ask(A,B,P);
}
int answer(int A,int B) {
if (A > B) swap(A,B);
Answer(A,B);
return 0;
}
vpii edges;
vi adjList[1400];
int solve2(vi v,int N) {
if (v.size() == 1) return 0;
else if (v.size() == 2) {
edges.pb(mp(v[0],v[1]));
return 0;
}
int i,j;
vi c,com[7];
swap(v[0],v[rand() % v.size()]);
for (i = 1; i < v.size(); i++) {
fill(P,P+N,0);
P[v[0]] = P[v[i]] = 1;
if (ask(v[0],v[i],P)) c.pb(v[i]),edges.pb(mp(v[0],v[i]));
}
for (i = 1; i < v.size(); i++) {
for (j = 0; j < c.size(); j++) {
if (c[j] == v[i]) break;
}
if (j == c.size()) {
fill(P,P+N,0);
for (j = 0; j < v.size(); j++) P[v[j]] = 1;
int l = 0,r = c.size()-1;
while (l < r) {
int m = (l+r) / 2;
for (j = l; j <= m; j++) P[c[j]] = 0;
if (ask(v[0],v[i],P)) l = m+1;
else r = m;
for (j = l; j <= m; j++) P[c[j]] = 1;
}
com[l].pb(v[i]);
}
else com[j].pb(v[i]);
}
for (i = 0; i < c.size(); i++) solve2(com[i],N);
return 0;
}
int solve(vi v,int N) {
if (v.size() == 1) return 0;
else if (v.size() == 2) {
answer(v[0],v[1]);
return 0;
}
int i,j;
vi path;
vector<vi> com;
swap(v[0],v[rand() % v.size()]);
swap(v[1],v[rand() % v.size()]);
fill(P,P+N,0);
for (i = 0; i < v.size(); i++) P[v[i]] = 1;
path.pb(v[0]),path.pb(v[1]);
for (i = 2; i < v.size(); i++) {
P[v[i]] = 0;
if (!ask(v[0],v[1],P)) path.pb(v[i]),P[v[i]] = 1;
}
solve2(path,N);
for (i = 0; i < edges.size(); i++) {
adjList[edges[i].first].pb(edges[i].second);
adjList[edges[i].second].pb(edges[i].first);
answer(edges[i].first,edges[i].second);
}
vi path2;
for (i = 0; i < path.size(); i++) {
if (adjList[path[i]].size() == 1) break;
}
int u = path[i],p = -1;
path2.pb(u);
while (1) {
for (i = 0; i < adjList[u].size(); i++) {
int v = adjList[u][i];
if (v != p) break;
}
if (i == adjList[u].size()) break;
else p = u,u = adjList[u][i],path2.pb(u);
}
for (i = 0; i < path.size(); i++) adjList[path[i]].clear();
path = path2,edges.clear();
com.resize(path.size());
for (i = 0; i < v.size(); i++) {
for (j = 0; j < path.size(); j++) {
if (v[i] == path[j]) break;
}
if (j < path.size()) com[j].pb(v[i]);
else {
fill(P,P+N,0);
for (j = 0; j < v.size(); j++) P[v[j]] = 1;
int l = 0,r = path.size()-1;
while (l < r) {
int m = (l+r+1) / 2;
P[path[m]] = 0;
if (ask(path[0],v[i],P)) r = m-1;
else l = m;
P[path[m]] = 1;
}
com[l].pb(v[i]);
}
}
for (i = 0; i < path.size(); i++) solve(com[i],N);
return 0;
}
void Detect(int T,int N) {
if (T == 1) {
int i,j,k;
for (i = 0; i < N; i++) {
for (j = i+1; j < N; j++) {
for (k = 0; k < N; k++) P[k] = 0;
P[i] = P[j] = 1;
if (ask(i,j,P)) answer(i,j);
}
}
}
else {
int i;
vi v;
for (i = 0; i < N; i++) v.pb(i);
solve(v,N);
}
}
Compilation message
park.cpp: In function 'int solve2(vi, int)':
park.cpp:81:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
81 | for (i = 1; i < v.size(); i++) {
| ~~^~~~~~~~~~
park.cpp:86:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
86 | for (i = 1; i < v.size(); i++) {
| ~~^~~~~~~~~~
park.cpp:87:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
87 | for (j = 0; j < c.size(); j++) {
| ~~^~~~~~~~~~
park.cpp:90:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
90 | if (j == c.size()) {
| ~~^~~~~~~~~~~
park.cpp:92:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
92 | for (j = 0; j < v.size(); j++) P[v[j]] = 1;
| ~~^~~~~~~~~~
park.cpp:106:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
106 | for (i = 0; i < c.size(); i++) solve2(com[i],N);
| ~~^~~~~~~~~~
park.cpp: In function 'int solve(vi, int)':
park.cpp:122:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
122 | for (i = 0; i < v.size(); i++) P[v[i]] = 1;
| ~~^~~~~~~~~~
park.cpp:124:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
124 | for (i = 2; i < v.size(); i++) {
| ~~^~~~~~~~~~
park.cpp:129:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
129 | for (i = 0; i < edges.size(); i++) {
| ~~^~~~~~~~~~~~~~
park.cpp:135:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
135 | for (i = 0; i < path.size(); i++) {
| ~~^~~~~~~~~~~~~
park.cpp:141:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
141 | for (i = 0; i < adjList[u].size(); i++) {
| ~~^~~~~~~~~~~~~~~~~~~
park.cpp:145:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
145 | if (i == adjList[u].size()) break;
| ~~^~~~~~~~~~~~~~~~~~~~
park.cpp:148:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
148 | for (i = 0; i < path.size(); i++) adjList[path[i]].clear();
| ~~^~~~~~~~~~~~~
park.cpp:151:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
151 | for (i = 0; i < v.size(); i++) {
| ~~^~~~~~~~~~
park.cpp:152:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
152 | for (j = 0; j < path.size(); j++) {
| ~~^~~~~~~~~~~~~
park.cpp:155:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
155 | if (j < path.size()) com[j].pb(v[i]);
| ~~^~~~~~~~~~~~~
park.cpp:158:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
158 | for (j = 0; j < v.size(); j++) P[v[j]] = 1;
| ~~^~~~~~~~~~
park.cpp:171:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
171 | for (i = 0; i < path.size(); i++) solve(com[i],N);
| ~~^~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
14 ms |
332 KB |
Output is correct |
3 |
Correct |
14 ms |
332 KB |
Output is correct |
4 |
Correct |
14 ms |
332 KB |
Output is correct |
5 |
Correct |
14 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
210 ms |
580 KB |
Output is correct |
2 |
Correct |
134 ms |
596 KB |
Output is correct |
3 |
Correct |
127 ms |
628 KB |
Output is correct |
4 |
Correct |
192 ms |
576 KB |
Output is correct |
5 |
Correct |
191 ms |
628 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
295 ms |
480 KB |
Output is correct |
2 |
Correct |
152 ms |
448 KB |
Output is correct |
3 |
Correct |
129 ms |
456 KB |
Output is correct |
4 |
Correct |
111 ms |
460 KB |
Output is correct |
5 |
Correct |
150 ms |
440 KB |
Output is correct |
6 |
Correct |
277 ms |
592 KB |
Output is correct |
7 |
Correct |
115 ms |
452 KB |
Output is correct |
8 |
Correct |
110 ms |
452 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
64 ms |
416 KB |
Output is correct |
2 |
Correct |
127 ms |
436 KB |
Output is correct |
3 |
Correct |
175 ms |
480 KB |
Output is correct |
4 |
Correct |
185 ms |
460 KB |
Output is correct |
5 |
Correct |
232 ms |
580 KB |
Output is correct |
6 |
Correct |
329 ms |
712 KB |
Output is correct |
7 |
Correct |
218 ms |
484 KB |
Output is correct |
8 |
Correct |
158 ms |
504 KB |
Output is correct |
9 |
Correct |
224 ms |
484 KB |
Output is correct |
10 |
Correct |
193 ms |
472 KB |
Output is correct |
11 |
Correct |
153 ms |
520 KB |
Output is correct |
12 |
Correct |
153 ms |
464 KB |
Output is correct |
13 |
Correct |
236 ms |
508 KB |
Output is correct |
14 |
Correct |
164 ms |
476 KB |
Output is correct |
15 |
Correct |
188 ms |
476 KB |
Output is correct |
16 |
Correct |
141 ms |
448 KB |
Output is correct |
17 |
Correct |
233 ms |
532 KB |
Output is correct |
18 |
Correct |
143 ms |
460 KB |
Output is correct |
19 |
Correct |
361 ms |
620 KB |
Output is correct |
20 |
Correct |
163 ms |
460 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
809 ms |
536 KB |
Wrong Answer[5] |
2 |
Halted |
0 ms |
0 KB |
- |