Submission #95857

# Submission time Handle Problem Language Result Execution time Memory
95857 2019-02-03T07:43:23 Z diamond_duke Park (JOI17_park) C++11
100 / 100
388 ms 804 KB
#include "park.h"
#include <algorithm>
#include <vector>
int can_go[2005], vis[2005], seq[2005], cnt, n;
bool in[2005], rem[2005];
std::vector<int> adj[2005];
inline void add_edge(int u, int v)
{
	if (u > v)
		std::swap(u, v);
	Answer(u, v);
	adj[u].push_back(v);
	adj[v].push_back(u);
}
inline bool query(int s, int t)
{
	if (s > t)
		std::swap(s, t);
	return Ask(s, t, can_go);
}
bool direct(int u)
{
	for (int i = 0; i < n; i++)
		can_go[i] = vis[i] == 1;
	can_go[u] = true;
	return query(0, u);
}
int get_nxt(int u)
{
	int l = 0, r = n - 1, res = -1;
	while (l <= r)
	{
		int m = l + r >> 1;
		for (int i = 0; i <= m; i++)
			can_go[i] = vis[i] != 2;
		for (int i = m + 1; i < n; i++)
			can_go[i] = vis[i] == 1;
		can_go[u] = true;
		if (query(0, u))
		{
			res = m;
			r = m - 1;
		}
		else
			l = m + 1;
	}
	return res;
}
void clear(int u)
{
	rem[u] = false;
	for (int v : adj[u])
	{
		if (rem[v])
			clear(v);
	}
}
void dfs(int u)
{
	seq[cnt++] = u;
	in[u] = true;
	for (int v : adj[u])
	{
		if (rem[v] && !in[v])
			dfs(v);
	}
}
void find_edge(int u)
{
	for (int i = 0; i < n; i++)
		rem[i] = vis[i] == 1;
	for (int rt = 0; rt < n; rt++)
	{
		while (rem[rt])
		{
			for (int i = 0; i < n; i++)
				can_go[i] = rem[i];
			can_go[u] = 1;
			if (!query(u, rt))
			{
				clear(rt);
				continue;
			}
			cnt = 0;
			for (int i = 0; i < n; i++)
				in[i] = false;
			dfs(rt);
			int l = 0, r = cnt - 1, res = -1;
			while (l <= r)
			{
				int m = l + r >> 1;
				for (int i = 0; i < cnt; i++)
					can_go[seq[i]] = i <= m;
				if (query(rt, u))
				{
					res = m;
					r = m - 1;
				}
				else
					l = m + 1;
			}
			add_edge(u, seq[res]);
			rem[seq[res]] = false;
		}
	}
}
void add(int u)
{
	vis[u] = 2;
	while (!direct(u))
		add(get_nxt(u));
	find_edge(u);
	vis[u] = 1;
}
void Detect(int T, int N)
{
	n = N;
	vis[0] = 1;
	for (int i = 1; i < n; i++)
	{
		if (!vis[i])
			add(i);
	}
}

Compilation message

park.cpp: In function 'int get_nxt(int)':
park.cpp:33:13: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   int m = l + r >> 1;
           ~~^~~
park.cpp: In function 'void find_edge(int)':
park.cpp:91:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
     int m = l + r >> 1;
             ~~^~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 7 ms 376 KB Output is correct
3 Correct 7 ms 376 KB Output is correct
4 Correct 16 ms 376 KB Output is correct
5 Correct 32 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 388 ms 664 KB Output is correct
2 Correct 134 ms 568 KB Output is correct
3 Correct 187 ms 672 KB Output is correct
4 Correct 356 ms 760 KB Output is correct
5 Correct 360 ms 712 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 179 ms 504 KB Output is correct
2 Correct 192 ms 652 KB Output is correct
3 Correct 197 ms 504 KB Output is correct
4 Correct 168 ms 636 KB Output is correct
5 Correct 221 ms 648 KB Output is correct
6 Correct 185 ms 504 KB Output is correct
7 Correct 183 ms 648 KB Output is correct
8 Correct 201 ms 648 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 100 ms 532 KB Output is correct
2 Correct 231 ms 536 KB Output is correct
3 Correct 232 ms 628 KB Output is correct
4 Correct 230 ms 544 KB Output is correct
5 Correct 251 ms 632 KB Output is correct
6 Correct 245 ms 636 KB Output is correct
7 Correct 260 ms 696 KB Output is correct
8 Correct 228 ms 636 KB Output is correct
9 Correct 231 ms 508 KB Output is correct
10 Correct 258 ms 504 KB Output is correct
11 Correct 253 ms 632 KB Output is correct
12 Correct 220 ms 632 KB Output is correct
13 Correct 284 ms 564 KB Output is correct
14 Correct 233 ms 764 KB Output is correct
15 Correct 280 ms 632 KB Output is correct
16 Correct 199 ms 792 KB Output is correct
17 Correct 365 ms 764 KB Output is correct
18 Correct 244 ms 508 KB Output is correct
19 Correct 312 ms 684 KB Output is correct
20 Correct 231 ms 556 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 293 ms 664 KB Output is correct
2 Correct 267 ms 760 KB Output is correct
3 Correct 238 ms 636 KB Output is correct
4 Correct 250 ms 664 KB Output is correct
5 Correct 284 ms 804 KB Output is correct
6 Correct 306 ms 636 KB Output is correct
7 Correct 280 ms 632 KB Output is correct
8 Correct 269 ms 556 KB Output is correct
9 Correct 266 ms 796 KB Output is correct
10 Correct 228 ms 636 KB Output is correct
11 Correct 233 ms 504 KB Output is correct
12 Correct 248 ms 660 KB Output is correct
13 Correct 228 ms 732 KB Output is correct
14 Correct 284 ms 604 KB Output is correct
15 Correct 259 ms 688 KB Output is correct
16 Correct 199 ms 632 KB Output is correct
17 Correct 362 ms 632 KB Output is correct
18 Correct 238 ms 684 KB Output is correct