#include <bits/stdc++.h>
#include "monster.h"
using namespace std;
namespace {
mt19937 mt(0x0606);
vector<int> stupid(vector<int> v) {
int N = v.size();
vector<vector<bool>> res(N, vector<bool>(N, false));
for (int i = 0; i < N; i++)
for (int j = i + 1; j < N; j++)
res[j][i] = !(res[i][j] = Query(v[i], v[j]));
vector<pair<int, int>> cnt(N);
for (int i = 0; i < N; i++)
cnt[i] = {count(res[i].begin(), res[i].end(), true), v[i]};
sort(cnt.begin(), cnt.end());
for (int i = 0; i < N; i++) v[i] = cnt[i].second;
if (Query(v[1], v[0])) swap(v[0], v[1]);
if (Query(v[N - 1], v[N - 2])) swap(v[N - 2], v[N - 1]);
return v;
}
vector<int> merge_sort(vector<int> v) {
if (v.size() == 1) return v;
shuffle(v.begin(), v.end(), mt);
int m = v.size() / 2;
vector<int> l(v.begin(), v.begin() + m), r(v.begin() + m, v.end());
l = merge_sort(l);
r = merge_sort(r);
int i = 0, j = 0;
for (int k = 0; k < v.size(); k++) {
if (i == l.size())
v[k] = r[j++];
else if (j == r.size())
v[k] = l[i++];
else if (Query(l[i], r[j]))
v[k] = r[j++];
else
v[k] = l[i++];
}
return v;
}
} // namespace
vector<int> Solve(int N) {
vector<int> v(N);
for (int i = 0; i < N; i++) v[i] = i;
v = merge_sort(v);
vector<int> s(v.begin(), v.begin() + min(10, N));
s = stupid(s);
int b = s[0];
v.erase(find(v.begin(), v.end(), b));
v.insert(v.begin(), b);
for (int i = 1; i < N; i++) {
int j = i;
while (j < N && Query(v[j], b)) j++;
reverse(v.begin() + i, v.begin() + min(j + 1, N));
b = v[i = j];
}
vector<int> S(N);
for (int i = 0; i < N; i++) S[v[i]] = i;
return S;
}
Compilation message
monster.cpp: In function 'std::vector<int> {anonymous}::merge_sort(std::vector<int>)':
monster.cpp:34:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
34 | for (int k = 0; k < v.size(); k++) {
| ~~^~~~~~~~~~
monster.cpp:35:11: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
35 | if (i == l.size())
| ~~^~~~~~~~~~~
monster.cpp:37:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
37 | else if (j == r.size())
| ~~^~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
200 KB |
Output is correct |
2 |
Correct |
1 ms |
228 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 |
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 |
256 KB |
Output is correct |
13 |
Correct |
1 ms |
256 KB |
Output is correct |
14 |
Correct |
1 ms |
200 KB |
Output is correct |
15 |
Correct |
1 ms |
200 KB |
Output is correct |
16 |
Correct |
18 ms |
200 KB |
Output is correct |
17 |
Correct |
16 ms |
200 KB |
Output is correct |
18 |
Correct |
20 ms |
200 KB |
Output is correct |
19 |
Correct |
7 ms |
200 KB |
Output is correct |
20 |
Correct |
15 ms |
200 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 |
200 KB |
Output is correct |
25 |
Correct |
1 ms |
200 KB |
Output is correct |
26 |
Correct |
20 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 |
16 ms |
200 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
200 KB |
Output is correct |
2 |
Correct |
1 ms |
228 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 |
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 |
256 KB |
Output is correct |
13 |
Correct |
1 ms |
256 KB |
Output is correct |
14 |
Correct |
1 ms |
200 KB |
Output is correct |
15 |
Correct |
1 ms |
200 KB |
Output is correct |
16 |
Correct |
18 ms |
200 KB |
Output is correct |
17 |
Correct |
16 ms |
200 KB |
Output is correct |
18 |
Correct |
20 ms |
200 KB |
Output is correct |
19 |
Correct |
7 ms |
200 KB |
Output is correct |
20 |
Correct |
15 ms |
200 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 |
200 KB |
Output is correct |
25 |
Correct |
1 ms |
200 KB |
Output is correct |
26 |
Correct |
20 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 |
16 ms |
200 KB |
Output is correct |
33 |
Correct |
107 ms |
200 KB |
Output is correct |
34 |
Correct |
56 ms |
200 KB |
Output is correct |
35 |
Correct |
44 ms |
304 KB |
Output is correct |
36 |
Correct |
60 ms |
200 KB |
Output is correct |
37 |
Correct |
98 ms |
200 KB |
Output is correct |
38 |
Correct |
106 ms |
200 KB |
Output is correct |
39 |
Correct |
104 ms |
200 KB |
Output is correct |
40 |
Correct |
125 ms |
200 KB |
Output is correct |
41 |
Correct |
115 ms |
200 KB |
Output is correct |
42 |
Correct |
99 ms |
288 KB |
Output is correct |
43 |
Correct |
89 ms |
200 KB |
Output is correct |
44 |
Correct |
109 ms |
200 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
105 ms |
200 KB |
Output is correct |
2 |
Correct |
101 ms |
200 KB |
Output is correct |
3 |
Correct |
108 ms |
200 KB |
Output is correct |
4 |
Correct |
115 ms |
256 KB |
Output is correct |
5 |
Correct |
115 ms |
200 KB |
Output is correct |
6 |
Correct |
96 ms |
200 KB |
Output is correct |
7 |
Correct |
88 ms |
200 KB |
Output is correct |
8 |
Correct |
117 ms |
200 KB |
Output is correct |
9 |
Correct |
107 ms |
292 KB |
Output is correct |
10 |
Correct |
111 ms |
200 KB |
Output is correct |
11 |
Correct |
96 ms |
200 KB |
Output is correct |
12 |
Correct |
117 ms |
200 KB |
Output is correct |
13 |
Correct |
54 ms |
200 KB |
Output is correct |
14 |
Correct |
83 ms |
200 KB |
Output is correct |
15 |
Correct |
57 ms |
200 KB |
Output is correct |
16 |
Correct |
70 ms |
200 KB |
Output is correct |
17 |
Correct |
52 ms |
200 KB |
Output is correct |
18 |
Correct |
70 ms |
200 KB |
Output is correct |