Submission #716374

# Submission time Handle Problem Language Result Execution time Memory
716374 2023-03-29T19:45:22 Z rainboy Monster Game (JOI21_monster) C++17
100 / 100
91 ms 328 KB
#include "monster.h"

using namespace std;

typedef vector<int> vi;

const int N = 1000;

int ii[N], jj[N];

void reverse(int *ii, int n) {
	int tmp;
	for (int i = 0, j = n - 1; i < j; i++, j--)
		tmp = ii[i], ii[i] = ii[j], ii[j] = tmp;
}

void rotate(int *ii, int n, int d) {
	d = (d % n + n) % n;
	for (int i = 0; i < n; i++)
		jj[(i + d) % n] = ii[i];
	for (int i = 0; i < n; i++)
		ii[i] = jj[i];
}

void solve(int *ii, int n, int h_, int i_) {
	if (h_ == n)
		return;
	if (i_ == -1) {
		if (n - h_ == 1)
			return;
		if (n - h_ == 2) {
			if (h_ > 0) {
				for (int u = 0; u < 3; u++)
					if (Query(ii[u], ii[h_]))
						return;
				reverse(ii + h_, 2);
			}
		} else if (Query(ii[h_], ii[h_ + 2])) {
			int h = h_ + 3;
			while (h < n && Query(ii[h_], ii[h]))
				h++;
			h--;
			if (h == h_ + 2) {
				if (h_ == 0) {
					solve(ii, n, h + 1, -1);
					while (!Query(ii[h_], ii[h_ + 3]))
						rotate(ii + h_, 3, 1);
					reverse(ii + h_, 3);
				} else
					while (1) {
						for (int u = 0; u < 3; u++)
							if (Query(ii[u], ii[h_ + 2])) {
								reverse(ii + h_, 3), solve(ii, n, h + 1, ii[h_ + 2]);
								return;
							}
						rotate(ii + h_, 3, 1);
					}
			} else {
				if (!Query(ii[h_ + 1], ii[h]))
					rotate(ii + h_, h - h_ + 1, 1);
				reverse(ii + h_, h - h_ + 1), solve(ii, n, h + 1, ii[h]);
			}
		} else {
			int h = h_ + 3;
			while (h < n && !Query(ii[h_], ii[h]))
				h++;
			rotate(ii + h_, h - h_ + 1, Query(ii[h_ + 1], ii[h]) ? -1 : -2);
			reverse(ii + h_, h - h_ + 1), solve(ii, n, h + 1, ii[h]);
		}
	} else
		for (int h = h_; h < n; h++)
			if (Query(i_, ii[h])) {
				reverse(ii + h_, h - h_ + 1), solve(ii, n, h + 1, ii[h]);
				return;
			}
}

vi Solve(int n) {
	for (int i = 0; i < n; i++) {
		int lower = -1, upper = i;
		while (upper - lower > 1) {
			int h = (lower + upper) / 2;
			if (Query(i, ii[h]))
				lower = h;
			else
				upper = h;
		}
		for (int h = i; h > upper; h--)
			ii[h] = ii[h - 1];
		ii[upper] = i;
	}
	solve(ii, n, 0, -1);
	vi aa(n, 0);
	for (int i = 0; i < n; i++)
		aa[ii[i]] = i;
	return aa;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 0 ms 208 KB Output is correct
4 Correct 0 ms 208 KB Output is correct
5 Correct 0 ms 208 KB Output is correct
6 Correct 1 ms 208 KB Output is correct
7 Correct 0 ms 208 KB Output is correct
8 Correct 1 ms 208 KB Output is correct
9 Correct 1 ms 208 KB Output is correct
10 Correct 1 ms 208 KB Output is correct
11 Correct 1 ms 208 KB Output is correct
12 Correct 0 ms 208 KB Output is correct
13 Correct 1 ms 208 KB Output is correct
14 Correct 1 ms 208 KB Output is correct
15 Correct 0 ms 208 KB Output is correct
16 Correct 10 ms 208 KB Output is correct
17 Correct 11 ms 208 KB Output is correct
18 Correct 15 ms 208 KB Output is correct
19 Correct 14 ms 208 KB Output is correct
20 Correct 11 ms 208 KB Output is correct
21 Correct 1 ms 208 KB Output is correct
22 Correct 1 ms 208 KB Output is correct
23 Correct 0 ms 208 KB Output is correct
24 Correct 1 ms 208 KB Output is correct
25 Correct 1 ms 208 KB Output is correct
26 Correct 13 ms 208 KB Output is correct
27 Correct 1 ms 208 KB Output is correct
28 Correct 0 ms 208 KB Output is correct
29 Correct 1 ms 208 KB Output is correct
30 Correct 1 ms 208 KB Output is correct
31 Correct 1 ms 208 KB Output is correct
32 Correct 11 ms 208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 0 ms 208 KB Output is correct
4 Correct 0 ms 208 KB Output is correct
5 Correct 0 ms 208 KB Output is correct
6 Correct 1 ms 208 KB Output is correct
7 Correct 0 ms 208 KB Output is correct
8 Correct 1 ms 208 KB Output is correct
9 Correct 1 ms 208 KB Output is correct
10 Correct 1 ms 208 KB Output is correct
11 Correct 1 ms 208 KB Output is correct
12 Correct 0 ms 208 KB Output is correct
13 Correct 1 ms 208 KB Output is correct
14 Correct 1 ms 208 KB Output is correct
15 Correct 0 ms 208 KB Output is correct
16 Correct 10 ms 208 KB Output is correct
17 Correct 11 ms 208 KB Output is correct
18 Correct 15 ms 208 KB Output is correct
19 Correct 14 ms 208 KB Output is correct
20 Correct 11 ms 208 KB Output is correct
21 Correct 1 ms 208 KB Output is correct
22 Correct 1 ms 208 KB Output is correct
23 Correct 0 ms 208 KB Output is correct
24 Correct 1 ms 208 KB Output is correct
25 Correct 1 ms 208 KB Output is correct
26 Correct 13 ms 208 KB Output is correct
27 Correct 1 ms 208 KB Output is correct
28 Correct 0 ms 208 KB Output is correct
29 Correct 1 ms 208 KB Output is correct
30 Correct 1 ms 208 KB Output is correct
31 Correct 1 ms 208 KB Output is correct
32 Correct 11 ms 208 KB Output is correct
33 Correct 59 ms 284 KB Output is correct
34 Correct 79 ms 272 KB Output is correct
35 Correct 39 ms 208 KB Output is correct
36 Correct 80 ms 208 KB Output is correct
37 Correct 53 ms 208 KB Output is correct
38 Correct 54 ms 272 KB Output is correct
39 Correct 85 ms 280 KB Output is correct
40 Correct 73 ms 276 KB Output is correct
41 Correct 67 ms 288 KB Output is correct
42 Correct 60 ms 280 KB Output is correct
43 Correct 74 ms 288 KB Output is correct
44 Correct 83 ms 276 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 75 ms 208 KB Output is correct
2 Correct 90 ms 284 KB Output is correct
3 Correct 90 ms 280 KB Output is correct
4 Correct 84 ms 276 KB Output is correct
5 Correct 77 ms 328 KB Output is correct
6 Correct 87 ms 328 KB Output is correct
7 Correct 91 ms 208 KB Output is correct
8 Correct 90 ms 272 KB Output is correct
9 Correct 81 ms 328 KB Output is correct
10 Correct 83 ms 272 KB Output is correct
11 Correct 50 ms 328 KB Output is correct
12 Correct 75 ms 276 KB Output is correct
13 Correct 79 ms 276 KB Output is correct
14 Correct 89 ms 284 KB Output is correct
15 Correct 89 ms 288 KB Output is correct
16 Correct 72 ms 328 KB Output is correct
17 Correct 82 ms 208 KB Output is correct
18 Correct 88 ms 280 KB Output is correct