#include "monster.h"
#include <bits/stdc++.h>
#define pb push_back
#define f first
#define sc second
using namespace std;
typedef long long int ll;
typedef string str;
#ifdef LOCAL
#define debug(v) for(auto x: v) cerr << x << " "; cerr << #v << "\n";
#endif
vector<vector<int>> QQ;
bool query(int a, int b){
if(a > b){
if(QQ[b][a] == -1) QQ[b][a] = Query(b, a);
return !QQ[b][a];
}
else{
if(QQ[a][b] == -1) QQ[a][b] = Query(a, b);
return QQ[a][b];
}
}
template<typename it>
void merge_sort(it a, it b){
int n = b-a;
if(n == 1) return;
merge_sort(a, a+n/2);
merge_sort(a+n/2, b);
int* ab = new int[n];
merge(a, a+n/2, a+n/2, b, ab, [](int x, int y){
return query(y, x);
});
for(int i = 0; i < n; i++) *(a+i) = *(ab+i);
}
vector<int> Solve(int n){
QQ = vector<vector<int>>(n, vector<int>(n, -1));
vector<int> sth(n);
for(int i = 0; i < n; i++) sth[i] = i;
merge_sort(sth.begin(), sth.end());
auto win = [=](int x){
vector<int> rt;
for(int i = 0; i < n; i++) if(i != x && query(x, i)) rt.pb(i);
return rt;
};
int n0 = n;
for(int i = 0; i < n0-1; i++){
if(i == 0){
auto s0 = win(sth[0]);
if(s0.size() == 1){
auto s1 = win(s0[0]);
if(s1.size() == 1){
continue;
}
}
}
if(i != 0 && query(sth[i-1], sth[i])) continue;
int a = i+2, b = n0-1;
while(a < b){
int md = (a+b)/2;
if(query(sth[md], sth[i])) b = md;
else{
if(md == a) a = md+1;
else{
if(query(sth[md-1], sth[i])) b = md-1;
else a = md+1;
}
}
}
if(i+2 >= n0 || query(sth[i], sth[a])){
if((i == 0 && win(sth[n0-1]).size() != 1) ||
(i != 0 && !query(sth[i-1], sth[n0-1])))
reverse(sth.begin()+i, sth.begin()+n0-1);
else reverse(sth.begin()+i, sth.begin()+n0);
i = n0;
}
else{
if((i == 0 && win(sth[a-1]).size() != 1) ||
(i != 0 && !query(sth[i-1], sth[a-1])))
reverse(sth.begin()+i, sth.begin()+a-1);
else reverse(sth.begin()+i, sth.begin()+a);
i = a-1;
}
}
vector<int> ans(n);
for(int i = 0; i < n; i++) ans[sth[i]] = i;
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
200 KB |
Output is correct |
2 |
Correct |
1 ms |
200 KB |
Output is correct |
3 |
Correct |
1 ms |
200 KB |
Output is correct |
4 |
Correct |
2 ms |
200 KB |
Output is correct |
5 |
Correct |
1 ms |
200 KB |
Output is correct |
6 |
Correct |
1 ms |
200 KB |
Output is correct |
7 |
Correct |
1 ms |
200 KB |
Output is correct |
8 |
Correct |
1 ms |
200 KB |
Output is correct |
9 |
Correct |
1 ms |
200 KB |
Output is correct |
10 |
Correct |
1 ms |
200 KB |
Output is correct |
11 |
Correct |
1 ms |
200 KB |
Output is correct |
12 |
Correct |
2 ms |
200 KB |
Output is correct |
13 |
Correct |
1 ms |
200 KB |
Output is correct |
14 |
Correct |
1 ms |
200 KB |
Output is correct |
15 |
Correct |
1 ms |
200 KB |
Output is correct |
16 |
Correct |
21 ms |
436 KB |
Output is correct |
17 |
Correct |
19 ms |
460 KB |
Output is correct |
18 |
Correct |
19 ms |
464 KB |
Output is correct |
19 |
Correct |
25 ms |
456 KB |
Output is correct |
20 |
Correct |
8 ms |
456 KB |
Output is correct |
21 |
Correct |
1 ms |
200 KB |
Output is correct |
22 |
Correct |
1 ms |
200 KB |
Output is correct |
23 |
Correct |
1 ms |
200 KB |
Output is correct |
24 |
Correct |
1 ms |
200 KB |
Output is correct |
25 |
Correct |
1 ms |
200 KB |
Output is correct |
26 |
Correct |
18 ms |
456 KB |
Output is correct |
27 |
Correct |
1 ms |
200 KB |
Output is correct |
28 |
Correct |
0 ms |
200 KB |
Output is correct |
29 |
Correct |
1 ms |
200 KB |
Output is correct |
30 |
Correct |
1 ms |
200 KB |
Output is correct |
31 |
Correct |
1 ms |
200 KB |
Output is correct |
32 |
Correct |
19 ms |
468 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
200 KB |
Output is correct |
2 |
Correct |
1 ms |
200 KB |
Output is correct |
3 |
Correct |
1 ms |
200 KB |
Output is correct |
4 |
Correct |
2 ms |
200 KB |
Output is correct |
5 |
Correct |
1 ms |
200 KB |
Output is correct |
6 |
Correct |
1 ms |
200 KB |
Output is correct |
7 |
Correct |
1 ms |
200 KB |
Output is correct |
8 |
Correct |
1 ms |
200 KB |
Output is correct |
9 |
Correct |
1 ms |
200 KB |
Output is correct |
10 |
Correct |
1 ms |
200 KB |
Output is correct |
11 |
Correct |
1 ms |
200 KB |
Output is correct |
12 |
Correct |
2 ms |
200 KB |
Output is correct |
13 |
Correct |
1 ms |
200 KB |
Output is correct |
14 |
Correct |
1 ms |
200 KB |
Output is correct |
15 |
Correct |
1 ms |
200 KB |
Output is correct |
16 |
Correct |
21 ms |
436 KB |
Output is correct |
17 |
Correct |
19 ms |
460 KB |
Output is correct |
18 |
Correct |
19 ms |
464 KB |
Output is correct |
19 |
Correct |
25 ms |
456 KB |
Output is correct |
20 |
Correct |
8 ms |
456 KB |
Output is correct |
21 |
Correct |
1 ms |
200 KB |
Output is correct |
22 |
Correct |
1 ms |
200 KB |
Output is correct |
23 |
Correct |
1 ms |
200 KB |
Output is correct |
24 |
Correct |
1 ms |
200 KB |
Output is correct |
25 |
Correct |
1 ms |
200 KB |
Output is correct |
26 |
Correct |
18 ms |
456 KB |
Output is correct |
27 |
Correct |
1 ms |
200 KB |
Output is correct |
28 |
Correct |
0 ms |
200 KB |
Output is correct |
29 |
Correct |
1 ms |
200 KB |
Output is correct |
30 |
Correct |
1 ms |
200 KB |
Output is correct |
31 |
Correct |
1 ms |
200 KB |
Output is correct |
32 |
Correct |
19 ms |
468 KB |
Output is correct |
33 |
Correct |
147 ms |
4216 KB |
Output is correct |
34 |
Correct |
81 ms |
4416 KB |
Output is correct |
35 |
Correct |
111 ms |
4228 KB |
Output is correct |
36 |
Correct |
124 ms |
4264 KB |
Output is correct |
37 |
Correct |
143 ms |
4488 KB |
Output is correct |
38 |
Correct |
114 ms |
4284 KB |
Output is correct |
39 |
Correct |
98 ms |
4168 KB |
Output is correct |
40 |
Correct |
106 ms |
4416 KB |
Output is correct |
41 |
Correct |
107 ms |
4256 KB |
Output is correct |
42 |
Correct |
134 ms |
4252 KB |
Output is correct |
43 |
Correct |
95 ms |
4392 KB |
Output is correct |
44 |
Correct |
105 ms |
4288 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Partially correct |
141 ms |
4228 KB |
Partially correct |
2 |
Partially correct |
119 ms |
4448 KB |
Partially correct |
3 |
Partially correct |
122 ms |
4252 KB |
Partially correct |
4 |
Partially correct |
132 ms |
4504 KB |
Partially correct |
5 |
Partially correct |
147 ms |
4284 KB |
Partially correct |
6 |
Partially correct |
135 ms |
4256 KB |
Partially correct |
7 |
Partially correct |
105 ms |
4288 KB |
Partially correct |
8 |
Partially correct |
145 ms |
4296 KB |
Partially correct |
9 |
Partially correct |
53 ms |
4264 KB |
Partially correct |
10 |
Partially correct |
115 ms |
4500 KB |
Partially correct |
11 |
Partially correct |
108 ms |
4284 KB |
Partially correct |
12 |
Partially correct |
137 ms |
4244 KB |
Partially correct |
13 |
Partially correct |
100 ms |
4260 KB |
Partially correct |
14 |
Partially correct |
98 ms |
4292 KB |
Partially correct |
15 |
Partially correct |
110 ms |
4368 KB |
Partially correct |
16 |
Partially correct |
102 ms |
4288 KB |
Partially correct |
17 |
Partially correct |
114 ms |
4252 KB |
Partially correct |
18 |
Partially correct |
111 ms |
4288 KB |
Partially correct |