Submission #428599

# Submission time Handle Problem Language Result Execution time Memory
428599 2021-06-15T13:10:03 Z pavement Park (JOI17_park) C++17
0 / 100
372 ms 460 KB
#include "park.h"
#include <bits/stdc++.h>
using namespace std;

mt19937 rng(29848);

#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 = 0; i <= mid; i++)
			Place[i] = 1;
		Place[l] = Place[r] = 1;
		if (l >= r ? Ask(r, l, Place) : Ask(l, r, Place)) ans = mid, hi = mid - 1;
		else lo = 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 = rng() % N;
	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);
}
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Wrong Answer[6]
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 62 ms 460 KB Output is correct
2 Incorrect 372 ms 460 KB Wrong Answer[5]
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 255 ms 408 KB Output is correct
2 Correct 160 ms 408 KB Output is correct
3 Correct 158 ms 412 KB Output is correct
4 Incorrect 300 ms 408 KB Wrong Answer[5]
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 101 ms 376 KB Output is correct
2 Correct 154 ms 416 KB Output is correct
3 Correct 152 ms 408 KB Output is correct
4 Correct 118 ms 412 KB Output is correct
5 Correct 127 ms 436 KB Output is correct
6 Correct 212 ms 456 KB Output is correct
7 Correct 148 ms 460 KB Output is correct
8 Correct 141 ms 412 KB Output is correct
9 Correct 97 ms 416 KB Output is correct
10 Incorrect 298 ms 440 KB Wrong Answer[5]
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 214 ms 440 KB Wrong Answer[6]
2 Halted 0 ms 0 KB -