#include "park.h"
#include <bits/stdc++.h>
using namespace std;
mt19937 rng(238479);
#define mp make_pair
#define mt make_tuple
#define pb push_back
static int N, Place[1405], link[1405], sz[1405];
map<tuple<int, int, vector<int> >, bool> ret;
bool query(int a, int b, int Place[]) {
vector<int> tmp;
for (int i = 0; i < N; i++) tmp.pb(Place[i]);
if (ret.find(mt(a, b, tmp)) != ret.end()) return ret[mt(a, b, tmp)];
else return ret[mt(a, b, tmp)] = Ask(a, b, Place);
}
int find(int x) {
if (x == link[x]) return x;
return link[x] = find(link[x]);
}
void unite(int a, int b) {
a = find(a);
b = find(b);
if (a == b) return;
if (sz[b] > sz[a]) swap(a, b);
sz[a] += sz[b];
link[b] = a;
}
void solve(int l, int r) {
if (find(l) == find(r)) return;
memset(Place, 0, sizeof Place);
Place[l] = Place[r] = 1;
if (l >= r ? Ask(r, l, Place) : Ask(l, r, Place)) {
l >= r ? Answer(r, l) : Answer(l, r);
unite(l, r);
return;
}
int lo = 0, hi = N - 1, ans = -1;
while (lo <= hi) {
int mid = (lo + hi) / 2;
memset(Place, 0, sizeof Place);
for (int i = mid; i < N; i++)
Place[i] = 1;
Place[l] = Place[r] = 1;
if (l >= r ? Ask(r, l, Place) : Ask(l, r, Place)) ans = mid, lo = mid + 1;
else hi = mid - 1;
}
solve(l, ans);
solve(ans, r);
}
void Detect(int T, int N) {
::N = N;
for (int i = 0; i < N; i++) {
link[i] = i;
sz[i] = 1;
}
vector<int> tmp;
int root = (T == 4 ? rng() % N : 0);
for (int i = 0; i < N; i++)
if (i != root) tmp.pb(i);
shuffle(tmp.begin(), tmp.end(), rng);
for (int i : tmp) solve(root, i);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
204 KB |
Wrong Answer[6] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
41 ms |
460 KB |
Output is correct |
2 |
Incorrect |
258 ms |
460 KB |
Wrong Answer[5] |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
144 ms |
392 KB |
Output is correct |
2 |
Correct |
174 ms |
388 KB |
Output is correct |
3 |
Correct |
173 ms |
388 KB |
Output is correct |
4 |
Correct |
241 ms |
396 KB |
Output is correct |
5 |
Correct |
147 ms |
392 KB |
Output is correct |
6 |
Correct |
170 ms |
392 KB |
Output is correct |
7 |
Correct |
178 ms |
400 KB |
Output is correct |
8 |
Correct |
204 ms |
392 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
169 ms |
332 KB |
Output is correct |
2 |
Incorrect |
239 ms |
392 KB |
Wrong Answer[5] |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
345 ms |
420 KB |
Wrong Answer[6] |
2 |
Halted |
0 ms |
0 KB |
- |