// Author: Wang, Yen-Jen
#include "park.h"
#include <bits/stdc++.h>
using namespace std;
static int N;
static int place[1400];
inline static void subtask1() {
memset(place , 0 , sizeof(place));
for(int i = 0; i < N; i++) {
for(int j = i + 1; j < N; j++) {
place[i] = 1;
place[j] = 1;
if(Ask(i , j , place)) Answer(i , j);
place[i] = 0;
place[j] = 0;
}
}
}
inline static void subtask2() {
for(int i = 0; i < N; i++) place[i] = 1;
vector<int> vec;
for(int i = 1; i < N - 1; i++) vec.push_back(i);
stable_sort(vec.begin() , vec.end() , [&](const int x , const int y) {
place[x] = 0;
int t = Ask(0 , y , place);
place[x] = 1;
return t == 0;
});
for(int i = 1; i < (int)vec.size(); i++) Answer(min(vec[i - 1] , vec[i]) , max(vec[i - 1] , vec[i]));
Answer(0 , vec[0]);
Answer(vec.back() , N - 1);
}
static void dfs_for_subtask3(int p , int l , int r , vector<int> &vec) {
if(l > r) return;
if(l == r) {
vec.push_back(l);
return;
}
int m = (l + r) >> 1;
if(!(l == m && l == p)) {
for(int i = 0; i < N; i++) place[i] = 1;
for(int i = l; i <= m; i++) place[i] = 0;
place[p] = 1;
if(!Ask(0 , p , place)) dfs_for_subtask3(p , l , m , vec);
}
if(m + 1 == r && r == p) return;
for(int i = 0; i < N; i++) place[i] = 1;
for(int i = m + 1; i <= r; i++) place[i] = 0;
place[p] = 1;
if(!Ask(0 , p , place)) dfs_for_subtask3(p , m + 1 , r , vec);
}
inline void subtask3() {
static int dep[1400];
for(int i = 0; i < N; i++) dep[i] = 0;
dep[0] = 0;
vector<pair<int , vector<int> > > vv;
for(int i = 1; i < N; i++) {
vector<int> vec;
vec.push_back(0);
dfs_for_subtask3(i , 1 , N - 1 , vec);
vv.push_back(make_pair(i , vec));
}
sort(vv.begin() , vv.end() , [&](const pair<int , vector<int> > &a , const pair<int , vector<int> > &b) {
return (int)a.second.size() < (int)b.second.size();
});
for(pair<int , vector<int> > &pp : vv) {
int p = 0;
for(int x : pp.second) {
if(dep[x] > dep[p]) p = x;
}
dep[pp.first] = dep[p] + 1;
Answer(min(p , pp.first) , max(p , pp.first));
}
}
void Detect(int T , int _N) {
N = _N;
if(N == 1) return;
else if(N == 2) {
Answer(0 , 1);
return;
}
if(T == 1) subtask1();
else if(T == 2) subtask2();
else subtask3();
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
2128 KB |
Output is correct |
2 |
Correct |
6 ms |
2128 KB |
Output is correct |
3 |
Correct |
6 ms |
2128 KB |
Output is correct |
4 |
Correct |
6 ms |
2128 KB |
Output is correct |
5 |
Correct |
6 ms |
2128 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
176 ms |
2128 KB |
Output is correct |
2 |
Correct |
56 ms |
2128 KB |
Output is correct |
3 |
Correct |
63 ms |
2128 KB |
Output is correct |
4 |
Correct |
176 ms |
2128 KB |
Output is correct |
5 |
Correct |
183 ms |
2128 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
856 ms |
2272 KB |
Wrong Answer[5] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
489 ms |
2128 KB |
Wrong Answer[5] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
899 ms |
2268 KB |
Wrong Answer[5] |
2 |
Halted |
0 ms |
0 KB |
- |