#include "park.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
static int Place[1400];
int a[2020];
int ask(int x, int y){return Ask(min(x, y), max(x, y), Place);}
void answer(int x, int y){Answer(min(x, y), max(x, y));}
bool cmp(int x, int y){
fill(Place, Place+1400, 1);
Place[y] = 0;
if (!ask(0, x)) return 0;
return 1;
}
int tmp[2020];
void _sort(int l, int r){
if (l>=r) return;
int m = (l+r)>>1;
_sort(l, m); _sort(m+1, r);
int pt = m+1, cnt = l;
for (int i=l;i<=m;i++){
while(pt<=r && !cmp(a[i], a[pt])){
tmp[cnt] = a[pt];
pt++, cnt++;
}
tmp[cnt] = a[i];
cnt++;
}
while(pt<=r){
tmp[cnt] = a[pt];
pt++, cnt++;
}
for (int i=l;i<=r;i++) a[i] = tmp[i];
}
vector<int> D[2020];
int mxdep = 0;
int getdep(int x){
fill(Place, Place+1400, 0);
Place[x] = 1;
int l = 0, r = mxdep, ret = mxdep;
while(l<=r){
int m = (l+r)>>1;
for (int i=0;i<=m;i++) {
for (auto &x:D[i]) Place[x] = 1;
}
if (ask(0, x)) ret = m, r = m-1;
else l = m+1;
for (int i=0;i<=m;i++) {
for (auto &x:D[i]) Place[x] = 0;
}
}
if (ret==mxdep) mxdep++;
D[ret+1].push_back(x);
return ret+1;
}
void Find(int x, int dep){
fill(Place, Place+1400, 0);
Place[x] = 1;
--dep;
for (int i=0;i<=dep-1;i++){
for (auto &x:D[i]) Place[x] = 1;
}
int pos = 0;
for (int z=1;z<(int)D[dep].size();z<<=1){
for (int i=0;i<(int)D[dep].size();i++) if (i&z) Place[D[dep][i]] = 1;
if (ask(0, x)) pos |= z;
for (int i=0;i<(int)D[dep].size();i++) if (i&z) Place[D[dep][i]] = 0;
}
answer(D[dep][pos], x);
for (int i=0;i<=dep-1;i++){
for (auto &x:D[i]) Place[x] = 0;
}
}
void Detect(int T, int N) {
for (int i=1;i<N;i++) a[i] = i;
_sort(1, N-1);
D[0].push_back(0);
for (int i=1;i<N;i++){
int dep = getdep(a[i]);
//printf("dep = %d, mxdep = %d\n", dep, mxdep);
Find(a[i], dep);
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
332 KB |
Wrong Answer[2] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
408 ms |
628 KB |
Output is correct |
2 |
Correct |
214 ms |
460 KB |
Output is correct |
3 |
Correct |
213 ms |
528 KB |
Output is correct |
4 |
Correct |
417 ms |
528 KB |
Output is correct |
5 |
Correct |
398 ms |
656 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
133 ms |
332 KB |
Wrong Answer[2] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
66 ms |
408 KB |
Wrong Answer[2] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
153 ms |
436 KB |
Wrong Answer[2] |
2 |
Halted |
0 ms |
0 KB |
- |