#include "monster.h"
#include <algorithm>
#include <random>
using namespace std;
mt19937 rng(177013);
namespace {
bool example_variable;
} // namespace
const int MAXN = 1001;
int hoh[MAXN][MAXN];
bool qr(int i, int j) {
if (hoh[i][j] != -1)
return hoh[i][j];
bool ans = Query(i, j);
hoh[i][j] = ans;
hoh[j][i] = !ans;
return ans;
}
int trim(vector<int> a, bool type) {
int m = a.size();
int cnt = 0;
vector<int> a0;
for (int i = 1; i < m; ++i) {
if (qr(a[0], a[i]) ^ type)
a0.push_back(a[i]);
}
if (a0.empty())
return a[0];
return trim(a0, type);
}
int fact(int n) {
int ans = 1;
for (int k = 2; k <= n; ++k)
ans *= k;
return ans;
}
void solve_bad(vector<int> a, vector<int>& ans, int l) {
int m = a.size();
for (int i = 0; i < m; ++i) {
ans[a[i]] = l;
for (int j = 0; j < m; ++j) {
if (i == j)
continue;
ans[a[i]] += qr(a[i], a[j]);
}
}
if (m < 4) {
sort(a.begin(), a.end());
int pmt = fact(m);
for (int t = 0; t < pmt; ++t) {
bool isok = true;
for (int i = 0; i + 1 < m && isok; ++i) {
isok &= qr(a[i], a[i + 1]);
for (int j = i + 2; j < m && isok; ++j)
isok &= qr(a[j], a[i]);
}
if (isok) {
for (int i = 0; i < m; ++i)
ans[a[i]] = l + i;
break;
}
next_permutation(a.begin(), a.end());
}
} else {
for (int i = 0; i < m; ++i) {
for (int j = i + 1; j < m; ++j) {
if (ans[a[i]] == ans[a[j]]) {
if (qr(a[i], a[j]))
swap(a[i], a[j]);
if (ans[a[i]] == l + 1)
--ans[a[j]];
else
++ans[a[i]];
}
}
}
}
}
void solve_part(vector<int> a, vector<int>& ans, int l) {
int cnt = 0;
int m = a.size();
if (m < 13) {
solve_bad(a, ans, l);
return;
}
for (int i = 1; i < m; ++i) {
cnt += qr(a[0], a[i]);
}
if (4 < cnt && cnt < m - 5) {
ans[a[0]] = l + cnt;
vector<int> low;
vector<int> high;
for (int i = 1; i < m; ++i) {
if (qr(a[0], a[i]))
low.push_back(a[i]);
else
high.push_back(a[i]);
}
int lowhigh = trim(low, 1);
int highlow = trim(high, 0);
low.erase(find(low.begin(), low.end(), lowhigh));
low.push_back(highlow);
high.erase(find(high.begin(), high.end(), highlow));
high.push_back(lowhigh);
solve_part(low, ans, l);
solve_part(high, ans, l + cnt + 1);
} else {
rotate(a.begin(), a.begin() + 1, a.end());
//if (high.size() > low.size()) {
//for (auto& x : a) {
//if (x == high[0]) {
//swap(x, a[0]);
//break;
//}
//}
//} else {
//for (auto& x : low) {
//if (x == low[0]) {
//swap(x, a[0]);
//break;
//}
//}
//}
solve_part(a, ans, l);
}
}
vector<int> Solve(int n) {
for (int i = 0; i < n; ++i) for (int j = 0; j < n; ++j)
hoh[i][j] = -1;
vector<int> vs(n);
for (int i = 0; i < n; ++i)
vs[i] = i;
shuffle(vs.begin(), vs.end(), rng);
vector<int> ans(n);
solve_part(vs, ans, 0);
return ans;
}
Compilation message
monster.cpp: In function 'int trim(std::vector<int>, bool)':
monster.cpp:28:9: warning: unused variable 'cnt' [-Wunused-variable]
28 | int cnt = 0;
| ^~~
monster.cpp: At global scope:
monster.cpp:10:6: warning: '{anonymous}::example_variable' defined but not used [-Wunused-variable]
10 | bool example_variable;
| ^~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
1 ms |
256 KB |
Output is correct |
3 |
Correct |
0 ms |
208 KB |
Output is correct |
4 |
Correct |
0 ms |
208 KB |
Output is correct |
5 |
Correct |
0 ms |
208 KB |
Output is correct |
6 |
Correct |
0 ms |
208 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 |
15 ms |
1076 KB |
Output is correct |
17 |
Correct |
19 ms |
1080 KB |
Output is correct |
18 |
Correct |
16 ms |
976 KB |
Output is correct |
19 |
Correct |
14 ms |
976 KB |
Output is correct |
20 |
Correct |
12 ms |
976 KB |
Output is correct |
21 |
Correct |
0 ms |
208 KB |
Output is correct |
22 |
Correct |
0 ms |
208 KB |
Output is correct |
23 |
Correct |
0 ms |
208 KB |
Output is correct |
24 |
Correct |
1 ms |
208 KB |
Output is correct |
25 |
Correct |
1 ms |
208 KB |
Output is correct |
26 |
Correct |
17 ms |
1080 KB |
Output is correct |
27 |
Correct |
0 ms |
208 KB |
Output is correct |
28 |
Correct |
1 ms |
208 KB |
Output is correct |
29 |
Correct |
1 ms |
208 KB |
Output is correct |
30 |
Correct |
1 ms |
208 KB |
Output is correct |
31 |
Correct |
1 ms |
276 KB |
Output is correct |
32 |
Correct |
19 ms |
1084 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
1 ms |
256 KB |
Output is correct |
3 |
Correct |
0 ms |
208 KB |
Output is correct |
4 |
Correct |
0 ms |
208 KB |
Output is correct |
5 |
Correct |
0 ms |
208 KB |
Output is correct |
6 |
Correct |
0 ms |
208 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 |
15 ms |
1076 KB |
Output is correct |
17 |
Correct |
19 ms |
1080 KB |
Output is correct |
18 |
Correct |
16 ms |
976 KB |
Output is correct |
19 |
Correct |
14 ms |
976 KB |
Output is correct |
20 |
Correct |
12 ms |
976 KB |
Output is correct |
21 |
Correct |
0 ms |
208 KB |
Output is correct |
22 |
Correct |
0 ms |
208 KB |
Output is correct |
23 |
Correct |
0 ms |
208 KB |
Output is correct |
24 |
Correct |
1 ms |
208 KB |
Output is correct |
25 |
Correct |
1 ms |
208 KB |
Output is correct |
26 |
Correct |
17 ms |
1080 KB |
Output is correct |
27 |
Correct |
0 ms |
208 KB |
Output is correct |
28 |
Correct |
1 ms |
208 KB |
Output is correct |
29 |
Correct |
1 ms |
208 KB |
Output is correct |
30 |
Correct |
1 ms |
208 KB |
Output is correct |
31 |
Correct |
1 ms |
276 KB |
Output is correct |
32 |
Correct |
19 ms |
1084 KB |
Output is correct |
33 |
Correct |
125 ms |
4224 KB |
Output is correct |
34 |
Correct |
93 ms |
4232 KB |
Output is correct |
35 |
Correct |
115 ms |
4220 KB |
Output is correct |
36 |
Correct |
144 ms |
4216 KB |
Output is correct |
37 |
Correct |
69 ms |
4216 KB |
Output is correct |
38 |
Correct |
100 ms |
4260 KB |
Output is correct |
39 |
Correct |
107 ms |
4224 KB |
Output is correct |
40 |
Correct |
94 ms |
4228 KB |
Output is correct |
41 |
Correct |
105 ms |
4220 KB |
Output is correct |
42 |
Correct |
137 ms |
4236 KB |
Output is correct |
43 |
Correct |
131 ms |
4336 KB |
Output is correct |
44 |
Correct |
120 ms |
4296 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Partially correct |
109 ms |
4468 KB |
Partially correct |
2 |
Partially correct |
110 ms |
4220 KB |
Partially correct |
3 |
Partially correct |
109 ms |
4272 KB |
Partially correct |
4 |
Partially correct |
106 ms |
4352 KB |
Partially correct |
5 |
Partially correct |
104 ms |
4372 KB |
Partially correct |
6 |
Incorrect |
190 ms |
4316 KB |
Wrong Answer [6] |
7 |
Halted |
0 ms |
0 KB |
- |