#include "monster.h"
#include <algorithm>
#include <iostream>
#include <numeric>
#include <cassert>
#include <vector>
#include <chrono>
#include <random>
typedef long long llong;
const int MAXN = 1000 + 10;
const int INF = 1e9;
std::mt19937 rng(15); //std::chrono::steady_clock::now().time_since_epoch().count());
std::vector <int> v;
std::vector <int> res;
void rec(int l, int r)
{
if (l == r)
{
return;
}
int mid = (l + r) / 2;
rec(l, mid);
rec(mid + 1, r);
int ptr = l;
int lPtr = l, rPtr = mid + 1;
while (lPtr <= mid || rPtr <= r)
{
if (lPtr == mid + 1)
{
res[ptr++] = v[rPtr++];
continue;
}
if (rPtr == r + 1)
{
res[ptr++] = v[lPtr++];
continue;
}
if (Query(v[rPtr], v[lPtr]))
{
res[ptr++] = v[lPtr++];
} else
{
res[ptr++] = v[rPtr++];
}
}
for (int i = l ; i <= r ; ++i)
{
v[i] = res[i];
}
}
int cnt[10];
std::vector <int> Solve(int n)
{
v.resize(n);
res.resize(n);
std::iota(v.begin(), v.end(), 0);
std::shuffle(v.begin(), v.end(), rng);
rec(0, n - 1);
for (int i = 0 ; i < std::min(10, n) ; ++i)
{
for (int j = i + 1 ; j < std::min(10, n) ; ++j)
{
if (Query(v[i], v[j])) cnt[i]++;
else cnt[j]++;
}
}
int min = -1;
for (int i = 0 ; i < std::min(10, n) ; ++i)
{
if (cnt[i] == 1)
{
if (min == -1 || Query(v[i], v[min])) min = i;
}
}
if (min != 0)
{
int beg = v[0];
int zero = v[min];
v.erase(v.begin() + min);
v.erase(v.begin());
v.insert(v.begin(), zero);
v.insert(v.begin() + min, beg);
}
int idx = 0;
for (int i = 1 ; i < n ; ++i)
{
if (Query(v[idx], v[i]))
{
std::reverse(v.begin() + idx + 1, v.begin() + i + 1);
idx = i;
}
}
for (int i = 0 ; i < n ; ++i)
{
res[v[i]] = i;
}
return res;
}
# |
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 |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
0 ms |
344 KB |
Output is correct |
12 |
Correct |
0 ms |
596 KB |
Output is correct |
13 |
Correct |
1 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 |
5 ms |
436 KB |
Output is correct |
17 |
Correct |
7 ms |
432 KB |
Output is correct |
18 |
Correct |
7 ms |
436 KB |
Output is correct |
19 |
Correct |
6 ms |
600 KB |
Output is correct |
20 |
Correct |
6 ms |
344 KB |
Output is correct |
21 |
Correct |
1 ms |
344 KB |
Output is correct |
22 |
Correct |
0 ms |
344 KB |
Output is correct |
23 |
Correct |
0 ms |
344 KB |
Output is correct |
24 |
Correct |
0 ms |
344 KB |
Output is correct |
25 |
Correct |
0 ms |
344 KB |
Output is correct |
26 |
Correct |
6 ms |
444 KB |
Output is correct |
27 |
Correct |
0 ms |
344 KB |
Output is correct |
28 |
Correct |
0 ms |
344 KB |
Output is correct |
29 |
Correct |
0 ms |
344 KB |
Output is correct |
30 |
Correct |
1 ms |
340 KB |
Output is correct |
31 |
Correct |
1 ms |
344 KB |
Output is correct |
32 |
Correct |
5 ms |
600 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 |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
0 ms |
344 KB |
Output is correct |
12 |
Correct |
0 ms |
596 KB |
Output is correct |
13 |
Correct |
1 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 |
5 ms |
436 KB |
Output is correct |
17 |
Correct |
7 ms |
432 KB |
Output is correct |
18 |
Correct |
7 ms |
436 KB |
Output is correct |
19 |
Correct |
6 ms |
600 KB |
Output is correct |
20 |
Correct |
6 ms |
344 KB |
Output is correct |
21 |
Correct |
1 ms |
344 KB |
Output is correct |
22 |
Correct |
0 ms |
344 KB |
Output is correct |
23 |
Correct |
0 ms |
344 KB |
Output is correct |
24 |
Correct |
0 ms |
344 KB |
Output is correct |
25 |
Correct |
0 ms |
344 KB |
Output is correct |
26 |
Correct |
6 ms |
444 KB |
Output is correct |
27 |
Correct |
0 ms |
344 KB |
Output is correct |
28 |
Correct |
0 ms |
344 KB |
Output is correct |
29 |
Correct |
0 ms |
344 KB |
Output is correct |
30 |
Correct |
1 ms |
340 KB |
Output is correct |
31 |
Correct |
1 ms |
344 KB |
Output is correct |
32 |
Correct |
5 ms |
600 KB |
Output is correct |
33 |
Correct |
46 ms |
600 KB |
Output is correct |
34 |
Correct |
45 ms |
428 KB |
Output is correct |
35 |
Correct |
40 ms |
428 KB |
Output is correct |
36 |
Correct |
54 ms |
436 KB |
Output is correct |
37 |
Correct |
40 ms |
592 KB |
Output is correct |
38 |
Correct |
49 ms |
420 KB |
Output is correct |
39 |
Correct |
40 ms |
428 KB |
Output is correct |
40 |
Correct |
38 ms |
420 KB |
Output is correct |
41 |
Correct |
67 ms |
592 KB |
Output is correct |
42 |
Correct |
39 ms |
420 KB |
Output is correct |
43 |
Correct |
49 ms |
424 KB |
Output is correct |
44 |
Correct |
42 ms |
440 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
40 ms |
424 KB |
Output is correct |
2 |
Correct |
40 ms |
592 KB |
Output is correct |
3 |
Correct |
50 ms |
344 KB |
Output is correct |
4 |
Correct |
38 ms |
424 KB |
Output is correct |
5 |
Correct |
40 ms |
440 KB |
Output is correct |
6 |
Correct |
43 ms |
444 KB |
Output is correct |
7 |
Correct |
37 ms |
424 KB |
Output is correct |
8 |
Correct |
43 ms |
424 KB |
Output is correct |
9 |
Correct |
40 ms |
424 KB |
Output is correct |
10 |
Correct |
46 ms |
592 KB |
Output is correct |
11 |
Correct |
51 ms |
596 KB |
Output is correct |
12 |
Correct |
60 ms |
424 KB |
Output is correct |
13 |
Correct |
40 ms |
424 KB |
Output is correct |
14 |
Correct |
30 ms |
424 KB |
Output is correct |
15 |
Correct |
20 ms |
592 KB |
Output is correct |
16 |
Correct |
22 ms |
592 KB |
Output is correct |
17 |
Correct |
36 ms |
424 KB |
Output is correct |
18 |
Correct |
22 ms |
436 KB |
Output is correct |