답안 #428585

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
428585 2021-06-15T13:01:43 Z pavement Park (JOI17_park) C++17
37 / 100
224 ms 496 KB
#include "park.h"
#include <bits/stdc++.h>
using namespace std;

#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;
	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;
	}
	if (ans == 0) {
		l >= r ? Answer(r, l) : Answer(l, r);
		unite(l, r);
	} else {
		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;
	for (int i = 1; i < N; i++) tmp.pb(i);
	random_shuffle(tmp.begin(), tmp.end());
	for (int i : tmp) solve(0, i);
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 204 KB Wrong Answer[6]
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 58 ms 464 KB Output is correct
2 Correct 115 ms 460 KB Output is correct
3 Correct 96 ms 496 KB Output is correct
4 Correct 38 ms 460 KB Output is correct
5 Correct 39 ms 476 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 146 ms 332 KB Output is correct
2 Correct 163 ms 404 KB Output is correct
3 Correct 173 ms 416 KB Output is correct
4 Correct 167 ms 412 KB Output is correct
5 Correct 142 ms 412 KB Output is correct
6 Correct 146 ms 452 KB Output is correct
7 Correct 148 ms 404 KB Output is correct
8 Correct 147 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 102 ms 380 KB Output is correct
2 Incorrect 130 ms 332 KB Wrong Answer[5]
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 224 ms 432 KB Wrong Answer[6]
2 Halted 0 ms 0 KB -