#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]))
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;
}
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())
| ~~~~^~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
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 |
Incorrect |
1 ms |
208 KB |
Wrong Answer [5] |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
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 |
Incorrect |
1 ms |
208 KB |
Wrong Answer [5] |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
101 ms |
304 KB |
Output is correct |
2 |
Correct |
64 ms |
432 KB |
Output is correct |
3 |
Correct |
87 ms |
312 KB |
Output is correct |
4 |
Correct |
97 ms |
208 KB |
Output is correct |
5 |
Correct |
90 ms |
300 KB |
Output is correct |
6 |
Correct |
78 ms |
332 KB |
Output is correct |
7 |
Correct |
74 ms |
312 KB |
Output is correct |
8 |
Correct |
74 ms |
304 KB |
Output is correct |
9 |
Incorrect |
90 ms |
208 KB |
Wrong Answer [4] |
10 |
Halted |
0 ms |
0 KB |
- |