#include "monster.h"
#include<bits/stdc++.h>
using namespace std;
//#define int long long
#define fi first
#define se second
#define pb push_back
//#define mp make_pair
#define foru(i, l, r) for(int i = l; i <= r; i++)
#define ford(i, r, l) for(int i = r; i >= l; i--)
typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef pair<ii, ii> iiii;
const int N = 1e5 + 5;
const int oo = 1e18 + 7, mod = 1e9 + 7;
int n, a[N];
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int rnd(int l, int r){
int temp = rng() % (r - l + 1);
temp = (temp + (r - l + 1)) % (r - l + 1);
return temp + l;
}
vector<int> er(vector<int> a, int x){
vector<int> b;
for(auto it : a) if(it != x) b.pb(it);
return b;
}
int deg[N];
map<ii, bool> mp;
void solve_brute(vector<int> x, int l, int r){
assert(x.size() == (r - l + 1));
if(x.size() == 1){
a[x[0]] = l;
return;
}
assert(x.size() != 3);
for(int i = 0; i < x.size(); i++){
for(int j = i + 1; j < x.size(); j++){
mp[{x[i], x[j]}] = Query(x[i], x[j]);
if(mp[{x[i], x[j]}]) deg[x[i]]++;
else deg[x[j]]++;
}
}
if(x.size() == 2){
if(!mp[{x[0], x[1]}]){
a[x[0]] = r, a[x[1]] = l;
}
else{
a[x[1]] = r, a[x[0]] = l;
}
return;
}
int mn0 = -1, mn1, mx0 = -1, mx1;
for(auto it : x){
if(deg[it] >= 2 && deg[it] <= x.size() - 3){
a[it] = l + deg[it];
}
if(deg[it] == 1){
if(mn0 == -1) mn0 = it;
else mn1 = it;
}
if(deg[it] == x.size() - 2){
if(mx0 == -1) mx0 = it;
else mx1 = it;
}
}
if(mp[{mn0, mn1}]){
a[mn0] = l; a[mn1] = l + 1;
}
else{
a[mn0] = l + 1; a[mn1] = l;
}
if(mp[{mx0, mx1}]){
a[mx0] = r - 1; a[mx1] = r;
}
else{
a[mx0] = r; a[mx1] = r - 1;
}
}
void solve(vector<int> x, int l, int r){
if(x.size() <= 16){
solve_brute(x, l, r);
return;
}
int temp;
vector<int> vc1, vc2;
while(1){
temp = x[rnd(0, x.size() - 1)];
vc1.clear(), vc2.clear();
for(auto it : x){
if(it == temp) continue;
if(!Query(it, temp)) vc1.pb(it);
else vc2.pb(it);
}
assert(vc1.size() && vc2.size());
if(vc1.size() >= 5 && vc2.size() >= 5) break;
}
//cout << temp << " " << l + vc1.size() << "\n";
a[temp] = l + vc1.size();
int w1 = vc1[0], w2 = vc2[0];
for(auto it : vc1){
if(it == w1) continue;
if(Query(it, w1)) w1 = it;
}
for(auto it : vc2){
if(it == w2) continue;
if(Query(w2, it)) w2 = it;
}
bool ck1 = 0, ck2 = 0;
a[w1] = l + vc1.size() + 1;
a[w2] = l + vc1.size() - 1;
vc1 = er(vc1, w1);
vc2 = er(vc2, w2);
solve(vc1, l, l + vc1.size() - 1);
solve(vc2, r - vc2.size() + 1, r);
}
vector<int> Solve(int _n){
n = _n;
vector<int> temp;
for(int i = 0; i < n; i++) temp.pb(i);
solve(temp, 0, n - 1);
//solve_brute(temp, 0, n - 1);
vector<int> temp2;
for(int i = 0; i < n; i++) temp2.pb(a[i]);
return temp2;
}
/*
void process(){
}
signed main(){
ios_base::sync_with_stdio(0);
process();
}
*/
Compilation message
monster.cpp:19:21: warning: overflow in conversion from 'double' to 'int' changes value from '1.0e+18' to '2147483647' [-Woverflow]
19 | const int oo = 1e18 + 7, mod = 1e9 + 7;
| ~~~~~^~~
In file included from /usr/include/c++/10/cassert:44,
from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:33,
from monster.cpp:2:
monster.cpp: In function 'void solve_brute(std::vector<int>, int, int)':
monster.cpp:42:18: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
42 | assert(x.size() == (r - l + 1));
| ~~~~~~~~~^~~~~~~~~~~~~~
monster.cpp:48:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
48 | for(int i = 0; i < x.size(); i++){
| ~~^~~~~~~~~~
monster.cpp:49:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
49 | for(int j = i + 1; j < x.size(); j++){
| ~~^~~~~~~~~~
monster.cpp:66:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
66 | if(deg[it] >= 2 && deg[it] <= x.size() - 3){
| ~~~~~~~~^~~~~~~~~~~~~~~
monster.cpp:73:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
73 | if(deg[it] == x.size() - 2){
| ~~~~~~~~^~~~~~~~~~~~~~~
monster.cpp: In function 'void solve(std::vector<int>, int, int)':
monster.cpp:121:7: warning: unused variable 'ck1' [-Wunused-variable]
121 | bool ck1 = 0, ck2 = 0;
| ^~~
monster.cpp:121:16: warning: unused variable 'ck2' [-Wunused-variable]
121 | bool ck1 = 0, ck2 = 0;
| ^~~
monster.cpp: In function 'void solve_brute(std::vector<int>, int, int)':
monster.cpp:88:22: warning: 'mx1' may be used uninitialized in this function [-Wmaybe-uninitialized]
88 | a[mx0] = r; a[mx1] = r - 1;
| ~~~~~~~^~~~~~~
monster.cpp:79:22: warning: 'mn1' may be used uninitialized in this function [-Wmaybe-uninitialized]
79 | a[mn0] = l; a[mn1] = l + 1;
| ~~~~~~~^~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
208 KB |
Output is correct |
2 |
Correct |
2 ms |
208 KB |
Output is correct |
3 |
Correct |
1 ms |
208 KB |
Output is correct |
4 |
Correct |
0 ms |
208 KB |
Output is correct |
5 |
Correct |
1 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 |
0 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 |
22 ms |
336 KB |
Output is correct |
17 |
Correct |
17 ms |
332 KB |
Output is correct |
18 |
Correct |
19 ms |
324 KB |
Output is correct |
19 |
Correct |
21 ms |
336 KB |
Output is correct |
20 |
Correct |
20 ms |
312 KB |
Output is correct |
21 |
Correct |
0 ms |
208 KB |
Output is correct |
22 |
Correct |
1 ms |
208 KB |
Output is correct |
23 |
Correct |
1 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 |
336 KB |
Output is correct |
27 |
Correct |
1 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 |
208 KB |
Output is correct |
32 |
Correct |
18 ms |
320 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
208 KB |
Output is correct |
2 |
Correct |
2 ms |
208 KB |
Output is correct |
3 |
Correct |
1 ms |
208 KB |
Output is correct |
4 |
Correct |
0 ms |
208 KB |
Output is correct |
5 |
Correct |
1 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 |
0 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 |
22 ms |
336 KB |
Output is correct |
17 |
Correct |
17 ms |
332 KB |
Output is correct |
18 |
Correct |
19 ms |
324 KB |
Output is correct |
19 |
Correct |
21 ms |
336 KB |
Output is correct |
20 |
Correct |
20 ms |
312 KB |
Output is correct |
21 |
Correct |
0 ms |
208 KB |
Output is correct |
22 |
Correct |
1 ms |
208 KB |
Output is correct |
23 |
Correct |
1 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 |
336 KB |
Output is correct |
27 |
Correct |
1 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 |
208 KB |
Output is correct |
32 |
Correct |
18 ms |
320 KB |
Output is correct |
33 |
Correct |
144 ms |
552 KB |
Output is correct |
34 |
Correct |
127 ms |
588 KB |
Output is correct |
35 |
Correct |
127 ms |
484 KB |
Output is correct |
36 |
Correct |
146 ms |
640 KB |
Output is correct |
37 |
Correct |
134 ms |
708 KB |
Output is correct |
38 |
Correct |
143 ms |
480 KB |
Output is correct |
39 |
Correct |
123 ms |
576 KB |
Output is correct |
40 |
Correct |
137 ms |
596 KB |
Output is correct |
41 |
Incorrect |
174 ms |
580 KB |
Wrong Answer [6] |
42 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Partially correct |
129 ms |
532 KB |
Partially correct |
2 |
Partially correct |
119 ms |
464 KB |
Partially correct |
3 |
Partially correct |
111 ms |
444 KB |
Partially correct |
4 |
Partially correct |
93 ms |
692 KB |
Partially correct |
5 |
Partially correct |
174 ms |
460 KB |
Partially correct |
6 |
Partially correct |
116 ms |
560 KB |
Partially correct |
7 |
Partially correct |
170 ms |
448 KB |
Partially correct |
8 |
Partially correct |
137 ms |
512 KB |
Partially correct |
9 |
Partially correct |
144 ms |
456 KB |
Partially correct |
10 |
Partially correct |
85 ms |
484 KB |
Partially correct |
11 |
Partially correct |
156 ms |
604 KB |
Partially correct |
12 |
Partially correct |
161 ms |
460 KB |
Partially correct |
13 |
Incorrect |
121 ms |
336 KB |
Wrong Answer [6] |
14 |
Halted |
0 ms |
0 KB |
- |