#include<bits/stdc++.h>
#include "monster.h"
using namespace std;
#define al(a) a.begin(), a.end()
random_device rd;
mt19937 rnd(1);
typedef int ll;
map<pair<ll, ll>, bool> m;
bool query(ll a, ll b) {
return (m.find(make_pair(a, b)) != m.end() ? m[make_pair(a, b)] : (m[make_pair(a, b)] = !(m[make_pair(b, a)] = Query(b, a))));
}
void s(vector<ll>& all) {
if (all.size() <= 1) {
return;
}
if (all.size() <= 24) {
vector<pair<ll, ll>> now;
map<ll, vector<ll>> big, sma;
for (ll i = 0; i < all.size(); i++) {
ll cb = 0;
for (ll j = 0; j < all.size(); j++) {
if (i != j) {
if (query(all[i], all[j])) {
sma[all[i]].push_back(all[j]);
} else {
cb++;
big[all[i]].push_back(all[j]);
}
}
}
now.emplace_back(cb, all[i]);
}
sort(now.rbegin(), now.rend());
if (sma[now[0].second].empty()) {
if (now.size() > 2 && find(al(sma[now[2].second]), now[1].second) != sma[now[2].second].end()) {
swap(now[1], now[2]);
}
} else {
if (find(al(sma[now[1].second]), now[0].second) != sma[now[1].second].end()) {
swap(now[0], now[1]);
}
}
if (big[now[now.size() - 1].second].empty()) {
if (now.size() > 2 && find(al(big[now[now.size() - 3].second]), now[now.size() - 2].second) != big[now[now.size() - 3].second].end()) {
swap(now[now.size() - 2], now[now.size() - 3]);
}
} else {
if (find(al(big[now[now.size() - 2].second]), now.back().second) != big[now[now.size() - 2].second].end()) {
swap(now[now.size() - 2], now.back());
}
}
for (ll i = 0; i < all.size(); i++) {
all[i] = now[i].second;
}
return;
}
ll x, now;
vector<ll> sm, bi;
do {
x = rnd() % all.size();
now = all[x];
sm.clear();
bi.clear();
for (ll j = 0; j < all.size(); j++) {
if (j != x) {
if (query(now, all[j])) {
sm.push_back(all[j]);
} else {
bi.push_back(all[j]);
}
}
}
} while (sm.size() < 6 || bi.size() < 6);
s(sm);
s(bi);
if (!sm.empty() && !bi.empty()) {
swap(sm.back(), bi[0]);
}
all.clear();
for (auto i : sm) {
all.push_back(i);
}
all.push_back(now);
for (auto i : bi) {
all.push_back(i);
}
}
vector<ll> Solve(ll n) {
vector<ll> all;
for (ll i = 0; i < n; i++) {
all.push_back(i);
}
s(all);
vector<ll> ans(n);
for (ll i = 0; i < n; i++) {
ans[all[i]] = i;
}
return ans;
}
Compilation message
monster.cpp: In function 'void s(std::vector<int>&)':
monster.cpp:26:34: warning: comparison of integer expressions of different signedness: 'll' {aka 'int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
26 | for (ll i = 0; i < all.size(); i++) {
| ~~^~~~~~~~~~~~
monster.cpp:28:42: warning: comparison of integer expressions of different signedness: 'll' {aka 'int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
28 | for (ll j = 0; j < all.size(); j++) {
| ~~^~~~~~~~~~~~
monster.cpp:59:34: warning: comparison of integer expressions of different signedness: 'll' {aka 'int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
59 | for (ll i = 0; i < all.size(); i++) {
| ~~^~~~~~~~~~~~
monster.cpp:71:34: warning: comparison of integer expressions of different signedness: 'll' {aka 'int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
71 | for (ll j = 0; j < all.size(); j++) {
| ~~^~~~~~~~~~~~
# |
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 |
444 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
344 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
0 ms |
344 KB |
Output is correct |
13 |
Correct |
0 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 |
12 ms |
984 KB |
Output is correct |
17 |
Correct |
13 ms |
1640 KB |
Output is correct |
18 |
Correct |
12 ms |
856 KB |
Output is correct |
19 |
Correct |
9 ms |
856 KB |
Output is correct |
20 |
Correct |
13 ms |
1020 KB |
Output is correct |
21 |
Correct |
0 ms |
344 KB |
Output is correct |
22 |
Correct |
0 ms |
596 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 |
15 ms |
1132 KB |
Output is correct |
27 |
Correct |
1 ms |
596 KB |
Output is correct |
28 |
Correct |
0 ms |
344 KB |
Output is correct |
29 |
Correct |
0 ms |
344 KB |
Output is correct |
30 |
Correct |
0 ms |
344 KB |
Output is correct |
31 |
Correct |
0 ms |
344 KB |
Output is correct |
32 |
Correct |
11 ms |
864 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 |
444 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
344 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
0 ms |
344 KB |
Output is correct |
13 |
Correct |
0 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 |
12 ms |
984 KB |
Output is correct |
17 |
Correct |
13 ms |
1640 KB |
Output is correct |
18 |
Correct |
12 ms |
856 KB |
Output is correct |
19 |
Correct |
9 ms |
856 KB |
Output is correct |
20 |
Correct |
13 ms |
1020 KB |
Output is correct |
21 |
Correct |
0 ms |
344 KB |
Output is correct |
22 |
Correct |
0 ms |
596 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 |
15 ms |
1132 KB |
Output is correct |
27 |
Correct |
1 ms |
596 KB |
Output is correct |
28 |
Correct |
0 ms |
344 KB |
Output is correct |
29 |
Correct |
0 ms |
344 KB |
Output is correct |
30 |
Correct |
0 ms |
344 KB |
Output is correct |
31 |
Correct |
0 ms |
344 KB |
Output is correct |
32 |
Correct |
11 ms |
864 KB |
Output is correct |
33 |
Correct |
73 ms |
3252 KB |
Output is correct |
34 |
Correct |
89 ms |
3064 KB |
Output is correct |
35 |
Correct |
84 ms |
2716 KB |
Output is correct |
36 |
Correct |
75 ms |
3220 KB |
Output is correct |
37 |
Correct |
79 ms |
2916 KB |
Output is correct |
38 |
Correct |
91 ms |
3600 KB |
Output is correct |
39 |
Correct |
79 ms |
3544 KB |
Output is correct |
40 |
Correct |
114 ms |
2368 KB |
Output is correct |
41 |
Correct |
87 ms |
2524 KB |
Output is correct |
42 |
Correct |
77 ms |
3448 KB |
Output is correct |
43 |
Correct |
88 ms |
3800 KB |
Output is correct |
44 |
Correct |
93 ms |
2812 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Partially correct |
89 ms |
3044 KB |
Partially correct |
2 |
Partially correct |
89 ms |
2632 KB |
Partially correct |
3 |
Partially correct |
91 ms |
3724 KB |
Partially correct |
4 |
Partially correct |
84 ms |
2988 KB |
Partially correct |
5 |
Partially correct |
97 ms |
3172 KB |
Partially correct |
6 |
Partially correct |
100 ms |
3316 KB |
Partially correct |
7 |
Partially correct |
114 ms |
3300 KB |
Partially correct |
8 |
Partially correct |
75 ms |
2536 KB |
Partially correct |
9 |
Partially correct |
98 ms |
2916 KB |
Partially correct |
10 |
Partially correct |
84 ms |
3104 KB |
Partially correct |
11 |
Partially correct |
111 ms |
3252 KB |
Partially correct |
12 |
Partially correct |
94 ms |
2908 KB |
Partially correct |
13 |
Incorrect |
148 ms |
4460 KB |
Wrong Answer [6] |
14 |
Halted |
0 ms |
0 KB |
- |