Submission #387114

# Submission time Handle Problem Language Result Execution time Memory
387114 2021-04-08T01:06:40 Z rainboy Fun Tour (APIO20_fun) C++11
31 / 100
131 ms 15488 KB
#include "fun.h"
#include <vector>

using namespace std;

const int N = 100000;

unsigned int X = 12345;

int rand_() {
	return (X *= 3) >> 1;
}

int dd[N];

void sort(int *ii, int l, int r) {
	while (l < r) {
		int i = l, j = l, k = r, i_ = ii[l + rand_() % (r - l)], tmp;

		while (j < k)
			if (dd[ii[j]] == dd[i_])
				j++;
			else if (dd[ii[j]] < dd[i_]) {
				tmp = ii[i], ii[i] = ii[j], ii[j] = tmp;
				i++, j++;
			} else {
				k--;
				tmp = ii[j], ii[j] = ii[k], ii[k] = tmp;
			}
		sort(ii, l, i);
		l = k;
	}
}

vector<int> createFunTour(int n, int q) {
	static int type[N], qu[3][N], cnt[3];
	vector<int> pp = vector<int>(n);
	int n_, h, i, i_, u, a, b, c, sz_;

	q = -1;
	sz_ = n + 1, u = -1;
	for (i = 0; i < n; i++) {
		int sz = attractionsBehind(0, i);

		if ((n - sz) * 2 <= n && sz_ > sz)
			sz_ = sz, u = i;
	}
	a = -1, b = -1, c = -1;
	for (i = 0; i < n; i++)
		if (i != u) {
			dd[i] = hoursRequired(u, i);
			if (dd[i] == 1) {
				if (a == -1)
					a = i;
				else if (b == -1)
					b = i;
				else
					c = i;
			}
		}
	for (i = 0; i < n; i++)
		if (i != u) {
			if (hoursRequired(a, i) == dd[i] - 1)
				type[i] = 0, qu[0][cnt[0]++] = i;
			else if (hoursRequired(b, i) == dd[i] - 1)
				type[i] = 1, qu[1][cnt[1]++] = i;
			else
				type[i] = 2, qu[2][cnt[2]++] = i;
		}
	if (cnt[0] == n / 2 || cnt[1] == n / 2)
		type[u] = 2, qu[2][cnt[2]++] = u;
	else
		type[u] = 0, qu[0][cnt[0]++] = u;
	for (h = 0; h < 3; h++)
		sort(qu[h], 0, cnt[h]);
	i_ = -1;
	for (h = 0; h < 3; h++)
		if (cnt[h]) {
			i = qu[h][cnt[h] - 1];
			if (i_ == -1 || dd[i_] < dd[i])
				i_ = i;
		}
	for (h = 0; h < 3; h++)
		if (cnt[h] == cnt[(h + 1) % 3] + cnt[(h + 2) % 3]) {
			i_ = qu[h][cnt[h] - 1];
			break;
		}
	i = i_, n_ = 0;
	while (n_ < n) {
		pp[n_++] = i;
		cnt[type[i]]--;
		if (n_ == n)
			break;
		i_ = -1;
		for (h = 0; h < 3; h++)
			if (h != type[i] && cnt[h]) {
				int i1 = qu[h][cnt[h] - 1];

				if (i_ == -1 || dd[i_] < dd[i1])
					i_ = i1;
			}
		for (h = 0; h < 3; h++)
			if (cnt[h] == cnt[(h + 1) % 3] + cnt[(h + 2) % 3]) {
				i_ = qu[h][cnt[h] - 1];
				break;
			}
		i = i_;
	}
	return pp;
}

Compilation message

fun.cpp: In function 'std::vector<int> createFunTour(int, int)':
fun.cpp:38:29: warning: variable 'c' set but not used [-Wunused-but-set-variable]
   38 |  int n_, h, i, i_, u, a, b, c, sz_;
      |                             ^
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 2 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 512 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 492 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 2 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 512 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 492 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 2 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
26 Correct 1 ms 364 KB Output is correct
27 Correct 1 ms 364 KB Output is correct
28 Correct 1 ms 364 KB Output is correct
29 Incorrect 1 ms 364 KB Tour is not fun
30 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 2 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 512 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 2 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 131 ms 15488 KB Output is correct
19 Correct 2 ms 492 KB Output is correct
20 Correct 3 ms 620 KB Output is correct
21 Correct 4 ms 876 KB Output is correct
22 Correct 7 ms 1260 KB Output is correct
23 Correct 13 ms 2412 KB Output is correct
24 Correct 18 ms 2924 KB Output is correct
25 Correct 72 ms 8964 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Incorrect 1 ms 364 KB Tour is not fun
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 2 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 512 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 492 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 2 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
26 Correct 1 ms 364 KB Output is correct
27 Correct 1 ms 364 KB Output is correct
28 Correct 1 ms 364 KB Output is correct
29 Incorrect 1 ms 364 KB Tour is not fun
30 Halted 0 ms 0 KB -