답안 #428689

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
428689 2021-06-15T13:51:55 Z pavement Park (JOI17_park) C++17
27 / 100
2000 ms 257700 KB
#include "park.h"
#include <bits/stdc++.h>
using namespace std;
 
mt19937 rng(128392);
 
#define mp make_pair
#define mt make_tuple
#define pb push_back
 
static int N, Place[1405], link[1405], sz[1405];
static bool vis[1405];
vector<int> adj[1405];
map<tuple<int, int, vector<int> >, bool> ret;
 
bool query(int a, int b, int Place[]) {
	if (a > b) return query(b, a, 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;
}
 
vector<int> sub;
 
void getsub(int n) {
	for (auto u : adj[n])
		getsub(u);
	sub.push_back(n);
}
 
int getmid(int l, int r, vector<int> s) {
	if (s.size() == 1) return s[0];
	assert(!s.empty());
	vector<int> ret;
	for (int i = 0; i < N; i++) Place[i] = 1;
	for (int i = 0; i < s.size() / 2; i++) Place[s[i]] = 0;
	if (!query(l, r, Place)) {
		for (int i = 0; i < s.size() / 2; i++) ret.pb(s[i]);
		return getmid(l, r, ret);
	} else {
		for (int i = s.size() / 2; i < s.size(); i++) ret.pb(s[i]);
		return getmid(l, r, ret);
	}
}
 
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 ? query(r, l, Place) : query(l, r, Place)) {
		l >= r ? Answer(r, l) : Answer(l, r);
		adj[l].pb(r);
		vis[l] = vis[r] = 1;
		unite(l, r);
		return;
	}
	vector<int> s;
	if (vis[l]) {
		sub.clear();
		getsub(l);
		sub.pop_back();
		sort(sub.begin(), sub.end());
		for (int i = 0; i < N; i++)
			if (i != l && i != r && (!vis[i] || binary_search(sub.begin(), sub.end(), i))) s.pb(i);
	} else {
		for (int i = 0; i < N; i++)
			if (i != l && i != r) s.pb(i);
	}
	int x = getmid(l, r, s);
	solve(l, x);
	solve(x, 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);
}

Compilation message

park.cpp: In function 'int getmid(int, int, std::vector<int>)':
park.cpp:51:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   51 |  for (int i = 0; i < s.size() / 2; i++) Place[s[i]] = 0;
      |                  ~~^~~~~~~~~~~~~~
park.cpp:53:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   53 |   for (int i = 0; i < s.size() / 2; i++) ret.pb(s[i]);
      |                   ~~^~~~~~~~~~~~~~
park.cpp:56:32: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   56 |   for (int i = s.size() / 2; i < s.size(); i++) ret.pb(s[i]);
      |                              ~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2100 ms 129620 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 350 ms 90144 KB Output is correct
2 Incorrect 931 ms 257700 KB Wrong Answer[5]
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 822 ms 136248 KB Output is correct
2 Correct 1054 ms 176576 KB Output is correct
3 Correct 933 ms 143064 KB Output is correct
4 Correct 1256 ms 210264 KB Output is correct
5 Correct 870 ms 140004 KB Output is correct
6 Correct 905 ms 155004 KB Output is correct
7 Correct 988 ms 173592 KB Output is correct
8 Correct 1106 ms 180144 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 526 ms 84284 KB Output is correct
2 Correct 1204 ms 198520 KB Output is correct
3 Correct 1278 ms 210632 KB Output is correct
4 Correct 1070 ms 182856 KB Output is correct
5 Correct 1046 ms 188976 KB Output is correct
6 Correct 1060 ms 208992 KB Output is correct
7 Correct 861 ms 159724 KB Output is correct
8 Incorrect 1398 ms 253144 KB Wrong Answer[5]
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2098 ms 119944 KB Time limit exceeded
2 Halted 0 ms 0 KB -