답안 #466033

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
466033 2021-08-17T15:11:02 Z nonsensenonsense1 Monster Game (JOI21_monster) C++17
100 / 100
124 ms 320 KB
#include "monster.h"
#include <vector>
#include <cstring>
#include <numeric>

const int N = 1000;
int a[N], aux[N], less[N];

void run(int l, int r) 
{
	if (r - l <= 1) return;
	int m = l + r >> 1;
	run(l, m);
	run(m, r);
	for (int i = 0, j = 0; i + j < r - l;) {
		if (l + i < m && (m + j == r || Query(a[m + j], a[l + i]))) {
			aux[i + j] = a[l + i];
			++i;
		}
		else {
			aux[i + j] = a[m + j];
			++j;
		}
	}
	memcpy(a + l, aux, r - l << 2);
}

std::vector<int> Solve(int n) 
{
	std::iota(a, a + n, 0);
	run(0, n);
	int k = std::min(n, 12);
	for (int i = 0; i < k; ++i) for (int j = i + 1; j < k; ++j) {
		if (Query(a[i], a[j])) ++less[i];
		else ++less[j];
	}
	int z = -1;
	for (int i = 0; i < k; ++i) if (less[i] == 1) if (z == -1 || Query(a[i], a[z])) z = i;
	int prev = 0;
	std::vector<int> ans(n);
	while (prev < n) {
		for (int i = z; i >= prev; --i) ans[a[i]] = prev + z - i;
		int z_ = z;
		if (z + 1 < n) for (++z; !Query(a[prev], a[z]); ++z);
		prev = z_ + 1;
	}
	return ans;
}

Compilation message

monster.cpp: In function 'void run(int, int)':
monster.cpp:12:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   12 |  int m = l + r >> 1;
      |          ~~^~~
monster.cpp:25:23: warning: suggest parentheses around '-' inside '<<' [-Wparentheses]
   25 |  memcpy(a + l, aux, r - l << 2);
      |                     ~~^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 200 KB Output is correct
2 Correct 1 ms 200 KB Output is correct
3 Correct 1 ms 200 KB Output is correct
4 Correct 1 ms 200 KB Output is correct
5 Correct 1 ms 200 KB Output is correct
6 Correct 0 ms 200 KB Output is correct
7 Correct 1 ms 200 KB Output is correct
8 Correct 1 ms 200 KB Output is correct
9 Correct 1 ms 200 KB Output is correct
10 Correct 1 ms 200 KB Output is correct
11 Correct 1 ms 200 KB Output is correct
12 Correct 1 ms 200 KB Output is correct
13 Correct 1 ms 200 KB Output is correct
14 Correct 1 ms 200 KB Output is correct
15 Correct 1 ms 200 KB Output is correct
16 Correct 21 ms 200 KB Output is correct
17 Correct 17 ms 200 KB Output is correct
18 Correct 17 ms 200 KB Output is correct
19 Correct 16 ms 200 KB Output is correct
20 Correct 13 ms 200 KB Output is correct
21 Correct 0 ms 200 KB Output is correct
22 Correct 1 ms 200 KB Output is correct
23 Correct 1 ms 200 KB Output is correct
24 Correct 1 ms 200 KB Output is correct
25 Correct 1 ms 288 KB Output is correct
26 Correct 5 ms 200 KB Output is correct
27 Correct 1 ms 200 KB Output is correct
28 Correct 1 ms 200 KB Output is correct
29 Correct 1 ms 200 KB Output is correct
30 Correct 1 ms 200 KB Output is correct
31 Correct 1 ms 200 KB Output is correct
32 Correct 11 ms 200 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 200 KB Output is correct
2 Correct 1 ms 200 KB Output is correct
3 Correct 1 ms 200 KB Output is correct
4 Correct 1 ms 200 KB Output is correct
5 Correct 1 ms 200 KB Output is correct
6 Correct 0 ms 200 KB Output is correct
7 Correct 1 ms 200 KB Output is correct
8 Correct 1 ms 200 KB Output is correct
9 Correct 1 ms 200 KB Output is correct
10 Correct 1 ms 200 KB Output is correct
11 Correct 1 ms 200 KB Output is correct
12 Correct 1 ms 200 KB Output is correct
13 Correct 1 ms 200 KB Output is correct
14 Correct 1 ms 200 KB Output is correct
15 Correct 1 ms 200 KB Output is correct
16 Correct 21 ms 200 KB Output is correct
17 Correct 17 ms 200 KB Output is correct
18 Correct 17 ms 200 KB Output is correct
19 Correct 16 ms 200 KB Output is correct
20 Correct 13 ms 200 KB Output is correct
21 Correct 0 ms 200 KB Output is correct
22 Correct 1 ms 200 KB Output is correct
23 Correct 1 ms 200 KB Output is correct
24 Correct 1 ms 200 KB Output is correct
25 Correct 1 ms 288 KB Output is correct
26 Correct 5 ms 200 KB Output is correct
27 Correct 1 ms 200 KB Output is correct
28 Correct 1 ms 200 KB Output is correct
29 Correct 1 ms 200 KB Output is correct
30 Correct 1 ms 200 KB Output is correct
31 Correct 1 ms 200 KB Output is correct
32 Correct 11 ms 200 KB Output is correct
33 Correct 90 ms 268 KB Output is correct
34 Correct 110 ms 276 KB Output is correct
35 Correct 63 ms 272 KB Output is correct
36 Correct 111 ms 200 KB Output is correct
37 Correct 79 ms 268 KB Output is correct
38 Correct 101 ms 280 KB Output is correct
39 Correct 115 ms 200 KB Output is correct
40 Correct 116 ms 272 KB Output is correct
41 Correct 82 ms 268 KB Output is correct
42 Correct 96 ms 272 KB Output is correct
43 Correct 43 ms 200 KB Output is correct
44 Correct 71 ms 200 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 71 ms 272 KB Output is correct
2 Correct 124 ms 272 KB Output is correct
3 Correct 114 ms 272 KB Output is correct
4 Correct 121 ms 268 KB Output is correct
5 Correct 101 ms 272 KB Output is correct
6 Correct 96 ms 200 KB Output is correct
7 Correct 99 ms 320 KB Output is correct
8 Correct 108 ms 268 KB Output is correct
9 Correct 49 ms 276 KB Output is correct
10 Correct 71 ms 272 KB Output is correct
11 Correct 124 ms 272 KB Output is correct
12 Correct 96 ms 272 KB Output is correct
13 Correct 73 ms 320 KB Output is correct
14 Correct 111 ms 284 KB Output is correct
15 Correct 47 ms 200 KB Output is correct
16 Correct 51 ms 200 KB Output is correct
17 Correct 49 ms 272 KB Output is correct
18 Correct 70 ms 200 KB Output is correct