#include "monster.h"
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
namespace {
bool example_variable;
} // namespace
vi solveP(int l, int r) {
if (l == r) return {l};
vi lp = solveP(l,(l+r)/2), rp = solveP(1+(l+r)/2,r);
vi ans;
int p1 = 0, p2 = 0;
while (p1 < lp.size() || p2 < rp.size()) {
if (p1 < lp.size() && p2 < rp.size()) {
if (!Query(lp[p1],rp[p2])) ans.push_back(rp[p2++]);
else ans.push_back(lp[p1++]);
}
else if (p1 < lp.size()) ans.push_back(lp[p1++]);
else ans.push_back(rp[p2++]);
}
return ans;
}
vector<int> badSolve(int N, vi ans) {
map<int,int> v;
for (int i = 0; i<N; ++i) {
for (int j = i+1; j<N; ++j) {
++v[Query(ans[i],ans[j]) ? ans[i] : ans[j]];
}
}
sort(ans.begin(), ans.end(), [&](int a, int b) {return v[a] < v[b];});
if (!Query(ans[0], ans[1])) swap(ans[0], ans[1]);
if (!Query(ans[N-2], ans[N-1])) swap(ans[N-2], ans[N-1]);
return ans;
}
vi Solve(int N) {
vi v = solveP(0,N-1);
reverse(v.begin(), v.end());
int k = min(N, 20);
vi partial(v.begin(), v.begin()+k);
int zero = badSolve(k,partial)[0];
int ind = find(v.begin(), v.end(), zero)-v.begin();
reverse(v.begin(), v.begin()+ind+1);
while (ind < N-1) {
int i = ind+1;
while (Query(v[i],v[ind])) ++i;
reverse(v.begin()+ind+1,v.begin()+i+1);
ind = i;
}
vi ret(N); for (int i = 0; i<N; ++i) ret[v[i]] = i;
return ret;
}
Compilation message
monster.cpp: In function 'vi solveP(int, int)':
monster.cpp:15:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
15 | while (p1 < lp.size() || p2 < rp.size()) {
| ~~~^~~~~~~~~~~
monster.cpp:15:33: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
15 | while (p1 < lp.size() || p2 < rp.size()) {
| ~~~^~~~~~~~~~~
monster.cpp:16:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
16 | if (p1 < lp.size() && p2 < rp.size()) {
| ~~~^~~~~~~~~~~
monster.cpp:16:34: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
16 | if (p1 < lp.size() && p2 < rp.size()) {
| ~~~^~~~~~~~~~~
monster.cpp:20:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
20 | else if (p1 < lp.size()) ans.push_back(lp[p1++]);
| ~~~^~~~~~~~~~~
monster.cpp: At global scope:
monster.cpp:7:6: warning: '{anonymous}::example_variable' defined but not used [-Wunused-variable]
7 | bool example_variable;
| ^~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
1 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
344 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
0 ms |
344 KB |
Output is correct |
13 |
Correct |
0 ms |
344 KB |
Output is correct |
14 |
Correct |
0 ms |
344 KB |
Output is correct |
15 |
Correct |
0 ms |
344 KB |
Output is correct |
16 |
Correct |
8 ms |
344 KB |
Output is correct |
17 |
Correct |
6 ms |
600 KB |
Output is correct |
18 |
Correct |
6 ms |
600 KB |
Output is correct |
19 |
Correct |
6 ms |
436 KB |
Output is correct |
20 |
Correct |
8 ms |
688 KB |
Output is correct |
21 |
Correct |
1 ms |
344 KB |
Output is correct |
22 |
Correct |
0 ms |
344 KB |
Output is correct |
23 |
Correct |
1 ms |
344 KB |
Output is correct |
24 |
Correct |
0 ms |
344 KB |
Output is correct |
25 |
Correct |
1 ms |
344 KB |
Output is correct |
26 |
Correct |
4 ms |
344 KB |
Output is correct |
27 |
Correct |
0 ms |
504 KB |
Output is correct |
28 |
Correct |
1 ms |
344 KB |
Output is correct |
29 |
Correct |
0 ms |
344 KB |
Output is correct |
30 |
Correct |
0 ms |
344 KB |
Output is correct |
31 |
Correct |
0 ms |
344 KB |
Output is correct |
32 |
Correct |
4 ms |
444 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
1 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
344 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
0 ms |
344 KB |
Output is correct |
13 |
Correct |
0 ms |
344 KB |
Output is correct |
14 |
Correct |
0 ms |
344 KB |
Output is correct |
15 |
Correct |
0 ms |
344 KB |
Output is correct |
16 |
Correct |
8 ms |
344 KB |
Output is correct |
17 |
Correct |
6 ms |
600 KB |
Output is correct |
18 |
Correct |
6 ms |
600 KB |
Output is correct |
19 |
Correct |
6 ms |
436 KB |
Output is correct |
20 |
Correct |
8 ms |
688 KB |
Output is correct |
21 |
Correct |
1 ms |
344 KB |
Output is correct |
22 |
Correct |
0 ms |
344 KB |
Output is correct |
23 |
Correct |
1 ms |
344 KB |
Output is correct |
24 |
Correct |
0 ms |
344 KB |
Output is correct |
25 |
Correct |
1 ms |
344 KB |
Output is correct |
26 |
Correct |
4 ms |
344 KB |
Output is correct |
27 |
Correct |
0 ms |
504 KB |
Output is correct |
28 |
Correct |
1 ms |
344 KB |
Output is correct |
29 |
Correct |
0 ms |
344 KB |
Output is correct |
30 |
Correct |
0 ms |
344 KB |
Output is correct |
31 |
Correct |
0 ms |
344 KB |
Output is correct |
32 |
Correct |
4 ms |
444 KB |
Output is correct |
33 |
Correct |
46 ms |
928 KB |
Output is correct |
34 |
Correct |
32 ms |
436 KB |
Output is correct |
35 |
Correct |
48 ms |
416 KB |
Output is correct |
36 |
Correct |
41 ms |
344 KB |
Output is correct |
37 |
Correct |
49 ms |
420 KB |
Output is correct |
38 |
Correct |
42 ms |
592 KB |
Output is correct |
39 |
Correct |
47 ms |
600 KB |
Output is correct |
40 |
Correct |
40 ms |
600 KB |
Output is correct |
41 |
Correct |
45 ms |
432 KB |
Output is correct |
42 |
Correct |
43 ms |
592 KB |
Output is correct |
43 |
Correct |
22 ms |
440 KB |
Output is correct |
44 |
Correct |
30 ms |
672 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
54 ms |
344 KB |
Output is correct |
2 |
Correct |
36 ms |
600 KB |
Output is correct |
3 |
Correct |
45 ms |
684 KB |
Output is correct |
4 |
Correct |
43 ms |
344 KB |
Output is correct |
5 |
Correct |
27 ms |
424 KB |
Output is correct |
6 |
Correct |
33 ms |
440 KB |
Output is correct |
7 |
Correct |
30 ms |
436 KB |
Output is correct |
8 |
Correct |
55 ms |
672 KB |
Output is correct |
9 |
Correct |
55 ms |
344 KB |
Output is correct |
10 |
Correct |
40 ms |
424 KB |
Output is correct |
11 |
Correct |
55 ms |
600 KB |
Output is correct |
12 |
Correct |
44 ms |
848 KB |
Output is correct |
13 |
Correct |
36 ms |
436 KB |
Output is correct |
14 |
Correct |
32 ms |
424 KB |
Output is correct |
15 |
Correct |
19 ms |
592 KB |
Output is correct |
16 |
Correct |
33 ms |
600 KB |
Output is correct |
17 |
Correct |
28 ms |
672 KB |
Output is correct |
18 |
Correct |
31 ms |
420 KB |
Output is correct |