#include "monster.h"
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
const int len = 12;
void print(string pre, vector<int> a) {
return;
cout << pre << " ";
for (int i = 0; i < a.size(); ++i) {
cout << a[i] << " ";
}
cout << "\n";
}
int higher[1 << len];
map<pair<int, int>, int> quer;
bool cmp(int a, int b, int N) {
if (a >= N) return true;
if (b >= N) return false;
//cout << a << " " << b << "\n";
bool q = Query(a, b);
if (q) higher[a]++; else higher[b]++;
return q;
}
bool compare(int a, int b, int N) {
if (quer[{a, b}] != 0) return quer[{a, b}] == 2;
bool q = cmp(a, b, N);
quer[{a, b}] = q ? 2 : 1;
quer[{b, a}] = q ? 1 : 2;
return q;
}
vector<int> sort(int l, int o, int N) {
if (l == 0) return std::vector<int>{o};
vector<int> a = sort(l - 1, o, N);
vector<int> b = sort(l - 1, o + (1 << (l - 1)), N);
vector<int> c(a.size() + b.size());
int iA = 0;
int iB = 0;
for (int i = 0; i < c.size(); ++i) {
if (iA < a.size() && iB < b.size()) {
if (compare(a[iA], b[iB], N)) {
c[i] = b[iB++];
} else {
c[i] = a[iA++];
}
} else {
if (iA == a.size()) {
c[i] = b[iB++];
} else {
c[i] = a[iA++];
}
}
}
return c;
}
void rev(vector<int> &T, int a, int b) {
for (int i = 0; i < (1 + b - a) / 2; ++i) {
swap(T[a + i], T[b - i]);
}
}
int findMin(int N) {
vector<int> low;
for (int i = 0; i < N; ++i) {
if (higher[i] <= 3) low.push_back(i);
}
print("possible: ", low);
int ii;
for (int i = 0; i < low.size(); ++i) {
ii = i + 1;
while (ii < low.size() && higher[i] <= 3) {
if (higher[ii] <= 3) compare(low[i], low[ii], N);
ii++;
}
}
vector<int> possible;
for (int i = 0; i < low.size(); ++i) {
if (higher[low[i]] <= 3) possible.push_back(low[i]);
}
print("possible: ", possible);
for (int i = 0; i < possible.size(); ++i) {
for (int j = i + 1; j < possible.size(); ++j) {
compare(possible[i], possible[j], N);
}
}
vector<int> min;
for (int i = 0; i < possible.size(); ++i) {
if (higher[possible[i]] == 1) min.push_back(possible[i]);
}
print("last: ", min);
//for (int i = 0; i < N; ++i) cout << higher[i]; cout << "\n";
return compare(min[0], min[1], N) ? min[0] : min[1];
}
std::vector<int> Solve(int N) {
vector<int> T = sort(len, 0, N);
int ind = -1;
int x = findMin(N);
for (int i = 0; i < N; ++i) {
if (T[i] == x) ind = i;
}
if (ind == -1) return {};
rev(T, 0, ind);
for (int s = ind; s < N - 1;) {
for (int i = s + 1; i < N; ++i) {
if (compare(T[s], T[i], N)) {
rev(T, s + 1, i);
s = i;
break;
}
if (i == N - 1) return {};
}
}
vector<int> erg = vector<int>(N, 0);
for (int i = 0; i < N; ++i) {
erg[T[i]] = i;
}
return erg;
}
Compilation message
monster.cpp: In function 'void print(std::string, std::vector<int>)':
monster.cpp:12:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
12 | for (int i = 0; i < a.size(); ++i) {
| ~~^~~~~~~~~~
monster.cpp: In function 'std::vector<int> sort(int, int, int)':
monster.cpp:45:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
45 | for (int i = 0; i < c.size(); ++i) {
| ~~^~~~~~~~~~
monster.cpp:46:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
46 | if (iA < a.size() && iB < b.size()) {
| ~~~^~~~~~~~~~
monster.cpp:46:33: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
46 | if (iA < a.size() && iB < b.size()) {
| ~~~^~~~~~~~~~
monster.cpp:53:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
53 | if (iA == a.size()) {
| ~~~^~~~~~~~~~~
monster.cpp: In function 'int findMin(int)':
monster.cpp:79:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
79 | for (int i = 0; i < low.size(); ++i) {
| ~~^~~~~~~~~~~~
monster.cpp:81:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
81 | while (ii < low.size() && higher[i] <= 3) {
| ~~~^~~~~~~~~~~~
monster.cpp:88:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
88 | for (int i = 0; i < low.size(); ++i) {
| ~~^~~~~~~~~~~~
monster.cpp:94:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
94 | for (int i = 0; i < possible.size(); ++i) {
| ~~^~~~~~~~~~~~~~~~~
monster.cpp:95:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
95 | for (int j = i + 1; j < possible.size(); ++j) {
| ~~^~~~~~~~~~~~~~~~~
monster.cpp:101:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
101 | for (int i = 0; i < possible.size(); ++i) {
| ~~^~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
3400 KB |
Output is correct |
2 |
Correct |
10 ms |
3400 KB |
Output is correct |
3 |
Correct |
10 ms |
3400 KB |
Output is correct |
4 |
Correct |
14 ms |
3400 KB |
Output is correct |
5 |
Correct |
12 ms |
3400 KB |
Output is correct |
6 |
Correct |
11 ms |
3392 KB |
Output is correct |
7 |
Correct |
11 ms |
3324 KB |
Output is correct |
8 |
Correct |
10 ms |
3400 KB |
Output is correct |
9 |
Correct |
10 ms |
3400 KB |
Output is correct |
10 |
Correct |
10 ms |
3400 KB |
Output is correct |
11 |
Correct |
10 ms |
3400 KB |
Output is correct |
12 |
Correct |
10 ms |
3400 KB |
Output is correct |
13 |
Correct |
10 ms |
3400 KB |
Output is correct |
14 |
Correct |
10 ms |
3364 KB |
Output is correct |
15 |
Correct |
11 ms |
3300 KB |
Output is correct |
16 |
Correct |
33 ms |
3608 KB |
Output is correct |
17 |
Correct |
30 ms |
3608 KB |
Output is correct |
18 |
Correct |
32 ms |
3532 KB |
Output is correct |
19 |
Correct |
26 ms |
3656 KB |
Output is correct |
20 |
Correct |
32 ms |
3532 KB |
Output is correct |
21 |
Correct |
10 ms |
3400 KB |
Output is correct |
22 |
Correct |
11 ms |
3400 KB |
Output is correct |
23 |
Correct |
10 ms |
3400 KB |
Output is correct |
24 |
Correct |
10 ms |
3400 KB |
Output is correct |
25 |
Correct |
12 ms |
3372 KB |
Output is correct |
26 |
Correct |
62 ms |
4100 KB |
Output is correct |
27 |
Correct |
11 ms |
3388 KB |
Output is correct |
28 |
Correct |
12 ms |
3296 KB |
Output is correct |
29 |
Correct |
11 ms |
3316 KB |
Output is correct |
30 |
Correct |
15 ms |
3400 KB |
Output is correct |
31 |
Correct |
11 ms |
3400 KB |
Output is correct |
32 |
Correct |
74 ms |
4360 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
3400 KB |
Output is correct |
2 |
Correct |
10 ms |
3400 KB |
Output is correct |
3 |
Correct |
10 ms |
3400 KB |
Output is correct |
4 |
Correct |
14 ms |
3400 KB |
Output is correct |
5 |
Correct |
12 ms |
3400 KB |
Output is correct |
6 |
Correct |
11 ms |
3392 KB |
Output is correct |
7 |
Correct |
11 ms |
3324 KB |
Output is correct |
8 |
Correct |
10 ms |
3400 KB |
Output is correct |
9 |
Correct |
10 ms |
3400 KB |
Output is correct |
10 |
Correct |
10 ms |
3400 KB |
Output is correct |
11 |
Correct |
10 ms |
3400 KB |
Output is correct |
12 |
Correct |
10 ms |
3400 KB |
Output is correct |
13 |
Correct |
10 ms |
3400 KB |
Output is correct |
14 |
Correct |
10 ms |
3364 KB |
Output is correct |
15 |
Correct |
11 ms |
3300 KB |
Output is correct |
16 |
Correct |
33 ms |
3608 KB |
Output is correct |
17 |
Correct |
30 ms |
3608 KB |
Output is correct |
18 |
Correct |
32 ms |
3532 KB |
Output is correct |
19 |
Correct |
26 ms |
3656 KB |
Output is correct |
20 |
Correct |
32 ms |
3532 KB |
Output is correct |
21 |
Correct |
10 ms |
3400 KB |
Output is correct |
22 |
Correct |
11 ms |
3400 KB |
Output is correct |
23 |
Correct |
10 ms |
3400 KB |
Output is correct |
24 |
Correct |
10 ms |
3400 KB |
Output is correct |
25 |
Correct |
12 ms |
3372 KB |
Output is correct |
26 |
Correct |
62 ms |
4100 KB |
Output is correct |
27 |
Correct |
11 ms |
3388 KB |
Output is correct |
28 |
Correct |
12 ms |
3296 KB |
Output is correct |
29 |
Correct |
11 ms |
3316 KB |
Output is correct |
30 |
Correct |
15 ms |
3400 KB |
Output is correct |
31 |
Correct |
11 ms |
3400 KB |
Output is correct |
32 |
Correct |
74 ms |
4360 KB |
Output is correct |
33 |
Correct |
120 ms |
4356 KB |
Output is correct |
34 |
Correct |
152 ms |
4408 KB |
Output is correct |
35 |
Correct |
129 ms |
4424 KB |
Output is correct |
36 |
Correct |
102 ms |
4416 KB |
Output is correct |
37 |
Correct |
121 ms |
4520 KB |
Output is correct |
38 |
Correct |
107 ms |
4416 KB |
Output is correct |
39 |
Correct |
109 ms |
4336 KB |
Output is correct |
40 |
Correct |
122 ms |
4404 KB |
Output is correct |
41 |
Correct |
62 ms |
4408 KB |
Output is correct |
42 |
Correct |
122 ms |
4340 KB |
Output is correct |
43 |
Incorrect |
232 ms |
6108 KB |
Wrong Answer [6] |
44 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Partially correct |
125 ms |
4472 KB |
Partially correct |
2 |
Partially correct |
130 ms |
4544 KB |
Partially correct |
3 |
Partially correct |
103 ms |
4496 KB |
Partially correct |
4 |
Partially correct |
129 ms |
4396 KB |
Partially correct |
5 |
Partially correct |
131 ms |
4516 KB |
Partially correct |
6 |
Incorrect |
254 ms |
6108 KB |
Wrong Answer [6] |
7 |
Halted |
0 ms |
0 KB |
- |