#include "monster.h"
#include <random>
#include <iostream>
#include <algorithm>
#define vi vector<int>
#define uid uniform_int_distribution<int>
using namespace std;
/*
Observations:
- P_i will win against min(1, max(P_i, N - 2)) opponents.
- Sorting with the comparator will give us an array such that it can be divided into
consecutive groups of [x, x - 1, ....], [y, y - 1, y - 2....], ...
- There are no two consecutive groups of size 1
- Each consecutive group's size is at most log N + 1.
*/
int done[1001][1001];
inline bool ask(int a, int b)
{
bool ret = 0;
if (a > b) {swap(a, b); ret = 1;}
if (done[a][b] == -1) done[a][b] = Query(a, b);
return ret ^ done[a][b];
}
int n, P[1001], A[1001];
inline void mergeSort(int L, int R)
{
if (L < R)
{
int M = L + R >> 1;
mergeSort(L, M);
mergeSort(M + 1, R);
for (int i = L; i <= R; i++) A[i] = P[i];
int l = L, r = M + 1;
for (int i = L; i <= R; i++)
{
if (l <= M && r <= R)
{
if (ask(A[r], A[l])) P[i] = A[l++];
else P[i] = A[r++];
}
else if (l <= M) P[i] = A[l++];
else P[i] = A[r++];
}
}
}
vector<int> Solve(int N)
{
vi ret(N); n = N;
for (int i = 0; i < N; i++)
{
for (int j = 0; j < N; j++) done[i][j] = -1;
P[i] = i;
}
mergeSort(0, N - 1);
int cnt = 0, prev = 1;
for (int i = 2; i < 22 && i <= prev + 11 && i < N; i++)
{
if (ask(P[0], P[i])) {cnt++; prev = i;}
}
int cur;
if (cnt > 1) {reverse(P, P + cnt + 1); cur = cnt;}
else if (cnt == 1 && prev > 2)
{
if (ask(P[1], P[prev])) {cur = 0;}
else {reverse(P, P + 2); cur = 1;}
}
else
{
int tp = 1;
for (int i = 3; i < 14 && i < N; i++)
{
if (ask(P[1], P[i])) {tp = 0; break;}
}
reverse(P, P + tp + 1); cur = tp;
}
for (int i = cur + 1; i < N; i++)
{
if (ask(P[cur], P[i]))
{
reverse(P + cur + 1, P + i + 1);
cur = i;
}
}
for (int i = 0; i < N; i++) ret[P[i]] = i;
return ret;
}
Compilation message
monster.cpp: In function 'void mergeSort(int, int)':
monster.cpp:35:19: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
35 | int M = L + R >> 1;
| ~~^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 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 |
1 ms |
200 KB |
Output is correct |
7 |
Correct |
1 ms |
328 KB |
Output is correct |
8 |
Correct |
1 ms |
328 KB |
Output is correct |
9 |
Correct |
1 ms |
200 KB |
Output is correct |
10 |
Correct |
1 ms |
328 KB |
Output is correct |
11 |
Correct |
1 ms |
328 KB |
Output is correct |
12 |
Correct |
1 ms |
296 KB |
Output is correct |
13 |
Correct |
1 ms |
328 KB |
Output is correct |
14 |
Correct |
1 ms |
328 KB |
Output is correct |
15 |
Correct |
1 ms |
328 KB |
Output is correct |
16 |
Correct |
13 ms |
968 KB |
Output is correct |
17 |
Correct |
12 ms |
968 KB |
Output is correct |
18 |
Correct |
12 ms |
1096 KB |
Output is correct |
19 |
Correct |
9 ms |
968 KB |
Output is correct |
20 |
Correct |
14 ms |
968 KB |
Output is correct |
21 |
Correct |
1 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 |
328 KB |
Output is correct |
25 |
Correct |
1 ms |
328 KB |
Output is correct |
26 |
Correct |
11 ms |
968 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 |
328 KB |
Output is correct |
30 |
Correct |
1 ms |
328 KB |
Output is correct |
31 |
Correct |
1 ms |
328 KB |
Output is correct |
32 |
Correct |
11 ms |
968 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 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 |
1 ms |
200 KB |
Output is correct |
7 |
Correct |
1 ms |
328 KB |
Output is correct |
8 |
Correct |
1 ms |
328 KB |
Output is correct |
9 |
Correct |
1 ms |
200 KB |
Output is correct |
10 |
Correct |
1 ms |
328 KB |
Output is correct |
11 |
Correct |
1 ms |
328 KB |
Output is correct |
12 |
Correct |
1 ms |
296 KB |
Output is correct |
13 |
Correct |
1 ms |
328 KB |
Output is correct |
14 |
Correct |
1 ms |
328 KB |
Output is correct |
15 |
Correct |
1 ms |
328 KB |
Output is correct |
16 |
Correct |
13 ms |
968 KB |
Output is correct |
17 |
Correct |
12 ms |
968 KB |
Output is correct |
18 |
Correct |
12 ms |
1096 KB |
Output is correct |
19 |
Correct |
9 ms |
968 KB |
Output is correct |
20 |
Correct |
14 ms |
968 KB |
Output is correct |
21 |
Correct |
1 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 |
328 KB |
Output is correct |
25 |
Correct |
1 ms |
328 KB |
Output is correct |
26 |
Correct |
11 ms |
968 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 |
328 KB |
Output is correct |
30 |
Correct |
1 ms |
328 KB |
Output is correct |
31 |
Correct |
1 ms |
328 KB |
Output is correct |
32 |
Correct |
11 ms |
968 KB |
Output is correct |
33 |
Correct |
69 ms |
4168 KB |
Output is correct |
34 |
Correct |
100 ms |
4168 KB |
Output is correct |
35 |
Correct |
53 ms |
4168 KB |
Output is correct |
36 |
Correct |
115 ms |
4168 KB |
Output is correct |
37 |
Correct |
111 ms |
4168 KB |
Output is correct |
38 |
Correct |
102 ms |
4168 KB |
Output is correct |
39 |
Correct |
105 ms |
4168 KB |
Output is correct |
40 |
Correct |
108 ms |
4168 KB |
Output is correct |
41 |
Correct |
42 ms |
4168 KB |
Output is correct |
42 |
Correct |
49 ms |
4168 KB |
Output is correct |
43 |
Correct |
54 ms |
4168 KB |
Output is correct |
44 |
Correct |
50 ms |
4168 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
77 ms |
4168 KB |
Output is correct |
2 |
Correct |
81 ms |
4168 KB |
Output is correct |
3 |
Correct |
95 ms |
4168 KB |
Output is correct |
4 |
Correct |
84 ms |
4168 KB |
Output is correct |
5 |
Correct |
78 ms |
4168 KB |
Output is correct |
6 |
Correct |
66 ms |
4168 KB |
Output is correct |
7 |
Correct |
87 ms |
4168 KB |
Output is correct |
8 |
Correct |
89 ms |
4168 KB |
Output is correct |
9 |
Correct |
48 ms |
4168 KB |
Output is correct |
10 |
Correct |
105 ms |
4168 KB |
Output is correct |
11 |
Correct |
112 ms |
4168 KB |
Output is correct |
12 |
Correct |
100 ms |
4168 KB |
Output is correct |
13 |
Correct |
86 ms |
4168 KB |
Output is correct |
14 |
Correct |
65 ms |
4168 KB |
Output is correct |
15 |
Correct |
64 ms |
4168 KB |
Output is correct |
16 |
Correct |
43 ms |
4168 KB |
Output is correct |
17 |
Correct |
101 ms |
4168 KB |
Output is correct |
18 |
Correct |
64 ms |
4168 KB |
Output is correct |