#include "monster.h"
#include <bits/stdc++.h>
#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define piii tuple<int, int, int>
using namespace std;
vector<int> merge(vector<int> v)
{
int n = v.size();
if (n == 1)
return v;
vector<int> l, r;
for (int i = 0; i < n; i++)
if (i < n / 2)
l.push_back(v[i]);
else
r.push_back(v[i]);
v.clear();
l = merge(l);
r = merge(r);
int ldx = 0, rdx = 0;
while (ldx < l.size() || rdx < r.size())
{
if (ldx >= l.size())
v.push_back(r[rdx++]);
else if (rdx >= r.size())
v.push_back(l[ldx++]);
else if (Query(l[ldx], r[rdx]))
v.push_back(r[rdx++]);
else
v.push_back(l[ldx++]);
}
return v;
}
vector<int> Solve(int N)
{
vector<int> v;
for (int i = 0; i < N; i++)
v.push_back(i);
v = merge(v);
for (int i = 0; i < N; i++)
cerr << v[i] << " \n"[i == N - 1];
int start = 0;
if (Query(v[0], v[1]))
start = 1;
else if (Query(v[2], v[0]))
{
if (Query(v[3], v[1]))
start = 2;
else
start = 1;
}
else if (Query(v[3], v[1]))
for (int j = 3; j < N; j++)
{
if (Query(v[2], v[j]))
{
start = 2;
break;
}
else if (Query(v[0], v[j]))
{
start = 3;
break;
}
else if (Query(v[1], v[j]))
{
start = 1;
break;
}
}
else
{
for (int i = 2; i < N - 2; i++)
if (Query(v[i + 2], v[i]))
{
start = i + 2;
break;
}
}
cerr << start << '\n';
reverse(v.begin(), v.begin() + start);
for (int i = start; i < N;)
{
int j = i;
while (Query(v[j], v[i - 1]))
j++;
j++;
reverse(v.begin() + i, v.begin() + j);
i = j;
}
// for (int i = 0; i < N; i++)
// cerr << v[i] << " \n"[i == N - 1];
vector<int> T(N);
for (int i = 0; i < N; i++)
T[v[i]] = i;
return T;
}
Compilation message
monster.cpp: In function 'std::vector<int> merge(std::vector<int>)':
monster.cpp:26:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
26 | while (ldx < l.size() || rdx < r.size())
| ~~~~^~~~~~~~~~
monster.cpp:26:34: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
26 | while (ldx < l.size() || rdx < r.size())
| ~~~~^~~~~~~~~~
monster.cpp:28:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
28 | if (ldx >= l.size())
| ~~~~^~~~~~~~~~~
monster.cpp:30:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
30 | else if (rdx >= r.size())
| ~~~~^~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
208 KB |
Output is correct |
2 |
Correct |
1 ms |
208 KB |
Output is correct |
3 |
Correct |
1 ms |
208 KB |
Output is correct |
4 |
Correct |
1 ms |
208 KB |
Output is correct |
5 |
Correct |
1 ms |
208 KB |
Output is correct |
6 |
Correct |
1 ms |
304 KB |
Output is correct |
7 |
Correct |
1 ms |
208 KB |
Output is correct |
8 |
Correct |
1 ms |
208 KB |
Output is correct |
9 |
Correct |
1 ms |
208 KB |
Output is correct |
10 |
Correct |
1 ms |
208 KB |
Output is correct |
11 |
Correct |
1 ms |
208 KB |
Output is correct |
12 |
Correct |
1 ms |
208 KB |
Output is correct |
13 |
Correct |
1 ms |
208 KB |
Output is correct |
14 |
Correct |
1 ms |
208 KB |
Output is correct |
15 |
Correct |
1 ms |
208 KB |
Output is correct |
16 |
Correct |
7 ms |
308 KB |
Output is correct |
17 |
Correct |
13 ms |
208 KB |
Output is correct |
18 |
Correct |
11 ms |
288 KB |
Output is correct |
19 |
Correct |
6 ms |
312 KB |
Output is correct |
20 |
Correct |
21 ms |
208 KB |
Output is correct |
21 |
Correct |
1 ms |
208 KB |
Output is correct |
22 |
Correct |
1 ms |
208 KB |
Output is correct |
23 |
Correct |
1 ms |
208 KB |
Output is correct |
24 |
Correct |
1 ms |
208 KB |
Output is correct |
25 |
Correct |
1 ms |
220 KB |
Output is correct |
26 |
Correct |
12 ms |
308 KB |
Output is correct |
27 |
Correct |
0 ms |
296 KB |
Output is correct |
28 |
Correct |
0 ms |
208 KB |
Output is correct |
29 |
Correct |
1 ms |
300 KB |
Output is correct |
30 |
Correct |
1 ms |
208 KB |
Output is correct |
31 |
Correct |
1 ms |
208 KB |
Output is correct |
32 |
Correct |
11 ms |
208 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
208 KB |
Output is correct |
2 |
Correct |
1 ms |
208 KB |
Output is correct |
3 |
Correct |
1 ms |
208 KB |
Output is correct |
4 |
Correct |
1 ms |
208 KB |
Output is correct |
5 |
Correct |
1 ms |
208 KB |
Output is correct |
6 |
Correct |
1 ms |
304 KB |
Output is correct |
7 |
Correct |
1 ms |
208 KB |
Output is correct |
8 |
Correct |
1 ms |
208 KB |
Output is correct |
9 |
Correct |
1 ms |
208 KB |
Output is correct |
10 |
Correct |
1 ms |
208 KB |
Output is correct |
11 |
Correct |
1 ms |
208 KB |
Output is correct |
12 |
Correct |
1 ms |
208 KB |
Output is correct |
13 |
Correct |
1 ms |
208 KB |
Output is correct |
14 |
Correct |
1 ms |
208 KB |
Output is correct |
15 |
Correct |
1 ms |
208 KB |
Output is correct |
16 |
Correct |
7 ms |
308 KB |
Output is correct |
17 |
Correct |
13 ms |
208 KB |
Output is correct |
18 |
Correct |
11 ms |
288 KB |
Output is correct |
19 |
Correct |
6 ms |
312 KB |
Output is correct |
20 |
Correct |
21 ms |
208 KB |
Output is correct |
21 |
Correct |
1 ms |
208 KB |
Output is correct |
22 |
Correct |
1 ms |
208 KB |
Output is correct |
23 |
Correct |
1 ms |
208 KB |
Output is correct |
24 |
Correct |
1 ms |
208 KB |
Output is correct |
25 |
Correct |
1 ms |
220 KB |
Output is correct |
26 |
Correct |
12 ms |
308 KB |
Output is correct |
27 |
Correct |
0 ms |
296 KB |
Output is correct |
28 |
Correct |
0 ms |
208 KB |
Output is correct |
29 |
Correct |
1 ms |
300 KB |
Output is correct |
30 |
Correct |
1 ms |
208 KB |
Output is correct |
31 |
Correct |
1 ms |
208 KB |
Output is correct |
32 |
Correct |
11 ms |
208 KB |
Output is correct |
33 |
Correct |
100 ms |
208 KB |
Output is correct |
34 |
Correct |
68 ms |
432 KB |
Output is correct |
35 |
Correct |
88 ms |
308 KB |
Output is correct |
36 |
Correct |
88 ms |
308 KB |
Output is correct |
37 |
Correct |
89 ms |
300 KB |
Output is correct |
38 |
Correct |
78 ms |
208 KB |
Output is correct |
39 |
Correct |
71 ms |
208 KB |
Output is correct |
40 |
Correct |
92 ms |
208 KB |
Output is correct |
41 |
Correct |
90 ms |
296 KB |
Output is correct |
42 |
Correct |
85 ms |
296 KB |
Output is correct |
43 |
Correct |
45 ms |
208 KB |
Output is correct |
44 |
Correct |
58 ms |
300 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
74 ms |
300 KB |
Output is correct |
2 |
Correct |
97 ms |
312 KB |
Output is correct |
3 |
Correct |
82 ms |
312 KB |
Output is correct |
4 |
Correct |
81 ms |
296 KB |
Output is correct |
5 |
Correct |
44 ms |
312 KB |
Output is correct |
6 |
Correct |
74 ms |
208 KB |
Output is correct |
7 |
Correct |
99 ms |
300 KB |
Output is correct |
8 |
Correct |
66 ms |
304 KB |
Output is correct |
9 |
Correct |
98 ms |
312 KB |
Output is correct |
10 |
Correct |
95 ms |
296 KB |
Output is correct |
11 |
Correct |
86 ms |
300 KB |
Output is correct |
12 |
Correct |
86 ms |
300 KB |
Output is correct |
13 |
Correct |
86 ms |
300 KB |
Output is correct |
14 |
Correct |
54 ms |
300 KB |
Output is correct |
15 |
Correct |
57 ms |
208 KB |
Output is correct |
16 |
Correct |
58 ms |
300 KB |
Output is correct |
17 |
Correct |
67 ms |
296 KB |
Output is correct |
18 |
Correct |
47 ms |
300 KB |
Output is correct |