#include <bits/stdc++.h>
#include "monster.h"
using namespace std;
namespace {
int nq;
bool myquery(int a, int b) {
nq++;
return Query(a,b);
}
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] = myquery(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 (myquery(v[1], v[0])) swap(v[0], v[1]);
if (myquery(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 (myquery(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 && myquery(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;
while(nq < 20100) myquery(0,1);
return S;
}
Compilation message
monster.cpp: In function 'std::vector<int> {anonymous}::merge_sort(std::vector<int>)':
monster.cpp:42:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
42 | for (int k = 0; k < v.size(); k++) {
| ~~^~~~~~~~~~
monster.cpp:43:11: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
43 | if (i == l.size())
| ~~^~~~~~~~~~~
monster.cpp:45:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
45 | else if (j == r.size())
| ~~^~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
98 ms |
200 KB |
Output is correct |
2 |
Correct |
191 ms |
200 KB |
Output is correct |
3 |
Correct |
214 ms |
200 KB |
Output is correct |
4 |
Correct |
167 ms |
200 KB |
Output is correct |
5 |
Correct |
132 ms |
200 KB |
Output is correct |
6 |
Correct |
226 ms |
200 KB |
Output is correct |
7 |
Correct |
169 ms |
200 KB |
Output is correct |
8 |
Correct |
228 ms |
200 KB |
Output is correct |
9 |
Correct |
181 ms |
200 KB |
Output is correct |
10 |
Correct |
238 ms |
240 KB |
Output is correct |
11 |
Correct |
228 ms |
200 KB |
Output is correct |
12 |
Correct |
195 ms |
200 KB |
Output is correct |
13 |
Correct |
200 ms |
200 KB |
Output is correct |
14 |
Correct |
199 ms |
200 KB |
Output is correct |
15 |
Correct |
157 ms |
240 KB |
Output is correct |
16 |
Correct |
155 ms |
200 KB |
Output is correct |
17 |
Correct |
167 ms |
200 KB |
Output is correct |
18 |
Correct |
206 ms |
200 KB |
Output is correct |
19 |
Correct |
182 ms |
200 KB |
Output is correct |
20 |
Correct |
219 ms |
200 KB |
Output is correct |
21 |
Correct |
195 ms |
256 KB |
Output is correct |
22 |
Correct |
101 ms |
200 KB |
Output is correct |
23 |
Correct |
216 ms |
200 KB |
Output is correct |
24 |
Correct |
226 ms |
200 KB |
Output is correct |
25 |
Correct |
207 ms |
200 KB |
Output is correct |
26 |
Correct |
163 ms |
200 KB |
Output is correct |
27 |
Correct |
232 ms |
200 KB |
Output is correct |
28 |
Correct |
220 ms |
200 KB |
Output is correct |
29 |
Correct |
208 ms |
200 KB |
Output is correct |
30 |
Correct |
159 ms |
200 KB |
Output is correct |
31 |
Correct |
208 ms |
200 KB |
Output is correct |
32 |
Correct |
174 ms |
200 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
98 ms |
200 KB |
Output is correct |
2 |
Correct |
191 ms |
200 KB |
Output is correct |
3 |
Correct |
214 ms |
200 KB |
Output is correct |
4 |
Correct |
167 ms |
200 KB |
Output is correct |
5 |
Correct |
132 ms |
200 KB |
Output is correct |
6 |
Correct |
226 ms |
200 KB |
Output is correct |
7 |
Correct |
169 ms |
200 KB |
Output is correct |
8 |
Correct |
228 ms |
200 KB |
Output is correct |
9 |
Correct |
181 ms |
200 KB |
Output is correct |
10 |
Correct |
238 ms |
240 KB |
Output is correct |
11 |
Correct |
228 ms |
200 KB |
Output is correct |
12 |
Correct |
195 ms |
200 KB |
Output is correct |
13 |
Correct |
200 ms |
200 KB |
Output is correct |
14 |
Correct |
199 ms |
200 KB |
Output is correct |
15 |
Correct |
157 ms |
240 KB |
Output is correct |
16 |
Correct |
155 ms |
200 KB |
Output is correct |
17 |
Correct |
167 ms |
200 KB |
Output is correct |
18 |
Correct |
206 ms |
200 KB |
Output is correct |
19 |
Correct |
182 ms |
200 KB |
Output is correct |
20 |
Correct |
219 ms |
200 KB |
Output is correct |
21 |
Correct |
195 ms |
256 KB |
Output is correct |
22 |
Correct |
101 ms |
200 KB |
Output is correct |
23 |
Correct |
216 ms |
200 KB |
Output is correct |
24 |
Correct |
226 ms |
200 KB |
Output is correct |
25 |
Correct |
207 ms |
200 KB |
Output is correct |
26 |
Correct |
163 ms |
200 KB |
Output is correct |
27 |
Correct |
232 ms |
200 KB |
Output is correct |
28 |
Correct |
220 ms |
200 KB |
Output is correct |
29 |
Correct |
208 ms |
200 KB |
Output is correct |
30 |
Correct |
159 ms |
200 KB |
Output is correct |
31 |
Correct |
208 ms |
200 KB |
Output is correct |
32 |
Correct |
174 ms |
200 KB |
Output is correct |
33 |
Correct |
177 ms |
200 KB |
Output is correct |
34 |
Correct |
221 ms |
200 KB |
Output is correct |
35 |
Correct |
219 ms |
200 KB |
Output is correct |
36 |
Correct |
185 ms |
200 KB |
Output is correct |
37 |
Correct |
220 ms |
200 KB |
Output is correct |
38 |
Correct |
196 ms |
200 KB |
Output is correct |
39 |
Correct |
205 ms |
200 KB |
Output is correct |
40 |
Correct |
169 ms |
200 KB |
Output is correct |
41 |
Correct |
147 ms |
200 KB |
Output is correct |
42 |
Correct |
174 ms |
200 KB |
Output is correct |
43 |
Correct |
159 ms |
200 KB |
Output is correct |
44 |
Correct |
145 ms |
200 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Partially correct |
205 ms |
200 KB |
Partially correct |
2 |
Partially correct |
219 ms |
200 KB |
Partially correct |
3 |
Partially correct |
219 ms |
200 KB |
Partially correct |
4 |
Partially correct |
223 ms |
200 KB |
Partially correct |
5 |
Partially correct |
185 ms |
200 KB |
Partially correct |
6 |
Partially correct |
186 ms |
200 KB |
Partially correct |
7 |
Partially correct |
180 ms |
200 KB |
Partially correct |
8 |
Partially correct |
206 ms |
200 KB |
Partially correct |
9 |
Partially correct |
130 ms |
200 KB |
Partially correct |
10 |
Partially correct |
116 ms |
200 KB |
Partially correct |
11 |
Partially correct |
228 ms |
200 KB |
Partially correct |
12 |
Partially correct |
219 ms |
200 KB |
Partially correct |
13 |
Partially correct |
180 ms |
200 KB |
Partially correct |
14 |
Partially correct |
179 ms |
200 KB |
Partially correct |
15 |
Partially correct |
179 ms |
200 KB |
Partially correct |
16 |
Partially correct |
213 ms |
284 KB |
Partially correct |
17 |
Partially correct |
217 ms |
200 KB |
Partially correct |
18 |
Partially correct |
207 ms |
200 KB |
Partially correct |