#include "monster.h"
#include <bits/stdc++.h>
using namespace std;
mt19937 rng(45345345);
vector<vector<int> > m(1000, vector<int>(1000, -1));
bool ask(int a, int b){
if(m[a][b] == -1){
m[a][b] = Query(a,b);
m[b][a] = 1 - m[a][b];
}
return m[a][b];
}
vector<int> solve(vector<int> v){
int N = v.size();
if(N <= 16){
vector<pair<int,int> > cnt(N);
vector<int> amb1, amb2;
for(int i = 0; i < N; i++){
cnt[i].second = v[i];
for(int j = 0; j < i; j++)
if(j != i){
if(ask(v[i],v[j])) cnt[i].first++;
else cnt[j].first++;
}
}
sort(cnt.begin(), cnt.end());
if(cnt[0].first == cnt[1].first){
if(!ask(cnt[0].second,cnt[1].second)) swap(cnt[0], cnt[1]);
}
if(cnt[1].first == cnt[2].first){
if(!ask(cnt[1].second,cnt[2].second)) swap(cnt[1], cnt[2]);
}
if(cnt[N-2].first == cnt[N-1].first){
if(!ask(cnt[N-2].second,cnt[N-1].second)) swap(cnt[N-2], cnt[N-1]);
}
if(cnt[N-3].first == cnt[N-2].first){
if(!ask(cnt[N-3].second,cnt[N-2].second)) swap(cnt[N-3], cnt[N-2]);
}
vector<int> res;
for(pair<int,int>& a : cnt) res.push_back(a.second);
return res;
}
vector<int> left, right;
int m = rng()%N;
while(true){
left.clear(), right.clear();
for(int i = 0; i < N; i++)
if(i != m){
if(ask(v[m], v[i])) left.push_back(v[i]);
else right.push_back(v[i]);
}
if(min(left.size(), right.size()) <= 5){
m = rng()%N;
continue;
}
break;
}
left = solve(left), right = solve(right);
if(!ask(left[left.size()-1], v[m])) swap(left[left.size()-1], right[0]);
vector<int> res;
for(int& a : left) res.push_back(a);
res.push_back(v[m]);
for(int& a : right) res.push_back(a);
return res;
}
std::vector<int> Solve(int N) {
vector<int> v;
for(int i = 0; i < N ; i++) v.push_back(i);
v = solve(v);
vector<int> T(N);
for(int i = 0; i < N; i++) T[v[i]] = i;
return T;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4184 KB |
Output is correct |
2 |
Correct |
2 ms |
4184 KB |
Output is correct |
3 |
Correct |
2 ms |
4184 KB |
Output is correct |
4 |
Correct |
2 ms |
4184 KB |
Output is correct |
5 |
Correct |
2 ms |
4184 KB |
Output is correct |
6 |
Correct |
2 ms |
4184 KB |
Output is correct |
7 |
Correct |
2 ms |
4184 KB |
Output is correct |
8 |
Correct |
2 ms |
4184 KB |
Output is correct |
9 |
Correct |
2 ms |
4184 KB |
Output is correct |
10 |
Correct |
2 ms |
4184 KB |
Output is correct |
11 |
Correct |
2 ms |
4184 KB |
Output is correct |
12 |
Correct |
2 ms |
4184 KB |
Output is correct |
13 |
Correct |
2 ms |
4184 KB |
Output is correct |
14 |
Correct |
2 ms |
4184 KB |
Output is correct |
15 |
Correct |
2 ms |
4184 KB |
Output is correct |
16 |
Correct |
9 ms |
4696 KB |
Output is correct |
17 |
Correct |
13 ms |
4404 KB |
Output is correct |
18 |
Correct |
10 ms |
4444 KB |
Output is correct |
19 |
Correct |
10 ms |
4440 KB |
Output is correct |
20 |
Correct |
9 ms |
4404 KB |
Output is correct |
21 |
Correct |
2 ms |
4184 KB |
Output is correct |
22 |
Correct |
2 ms |
4184 KB |
Output is correct |
23 |
Correct |
2 ms |
4184 KB |
Output is correct |
24 |
Correct |
2 ms |
4184 KB |
Output is correct |
25 |
Correct |
2 ms |
4184 KB |
Output is correct |
26 |
Correct |
10 ms |
4612 KB |
Output is correct |
27 |
Correct |
3 ms |
4180 KB |
Output is correct |
28 |
Correct |
2 ms |
4184 KB |
Output is correct |
29 |
Correct |
2 ms |
4184 KB |
Output is correct |
30 |
Correct |
2 ms |
4184 KB |
Output is correct |
31 |
Correct |
2 ms |
4184 KB |
Output is correct |
32 |
Correct |
9 ms |
4400 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4184 KB |
Output is correct |
2 |
Correct |
2 ms |
4184 KB |
Output is correct |
3 |
Correct |
2 ms |
4184 KB |
Output is correct |
4 |
Correct |
2 ms |
4184 KB |
Output is correct |
5 |
Correct |
2 ms |
4184 KB |
Output is correct |
6 |
Correct |
2 ms |
4184 KB |
Output is correct |
7 |
Correct |
2 ms |
4184 KB |
Output is correct |
8 |
Correct |
2 ms |
4184 KB |
Output is correct |
9 |
Correct |
2 ms |
4184 KB |
Output is correct |
10 |
Correct |
2 ms |
4184 KB |
Output is correct |
11 |
Correct |
2 ms |
4184 KB |
Output is correct |
12 |
Correct |
2 ms |
4184 KB |
Output is correct |
13 |
Correct |
2 ms |
4184 KB |
Output is correct |
14 |
Correct |
2 ms |
4184 KB |
Output is correct |
15 |
Correct |
2 ms |
4184 KB |
Output is correct |
16 |
Correct |
9 ms |
4696 KB |
Output is correct |
17 |
Correct |
13 ms |
4404 KB |
Output is correct |
18 |
Correct |
10 ms |
4444 KB |
Output is correct |
19 |
Correct |
10 ms |
4440 KB |
Output is correct |
20 |
Correct |
9 ms |
4404 KB |
Output is correct |
21 |
Correct |
2 ms |
4184 KB |
Output is correct |
22 |
Correct |
2 ms |
4184 KB |
Output is correct |
23 |
Correct |
2 ms |
4184 KB |
Output is correct |
24 |
Correct |
2 ms |
4184 KB |
Output is correct |
25 |
Correct |
2 ms |
4184 KB |
Output is correct |
26 |
Correct |
10 ms |
4612 KB |
Output is correct |
27 |
Correct |
3 ms |
4180 KB |
Output is correct |
28 |
Correct |
2 ms |
4184 KB |
Output is correct |
29 |
Correct |
2 ms |
4184 KB |
Output is correct |
30 |
Correct |
2 ms |
4184 KB |
Output is correct |
31 |
Correct |
2 ms |
4184 KB |
Output is correct |
32 |
Correct |
9 ms |
4400 KB |
Output is correct |
33 |
Correct |
63 ms |
4696 KB |
Output is correct |
34 |
Correct |
55 ms |
4696 KB |
Output is correct |
35 |
Correct |
65 ms |
4964 KB |
Output is correct |
36 |
Correct |
60 ms |
5172 KB |
Output is correct |
37 |
Correct |
65 ms |
4916 KB |
Output is correct |
38 |
Correct |
58 ms |
4972 KB |
Output is correct |
39 |
Correct |
65 ms |
4956 KB |
Output is correct |
40 |
Correct |
53 ms |
4932 KB |
Output is correct |
41 |
Correct |
56 ms |
5192 KB |
Output is correct |
42 |
Correct |
57 ms |
4956 KB |
Output is correct |
43 |
Correct |
61 ms |
4952 KB |
Output is correct |
44 |
Correct |
60 ms |
4924 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Partially correct |
58 ms |
4940 KB |
Partially correct |
2 |
Partially correct |
69 ms |
4688 KB |
Partially correct |
3 |
Partially correct |
62 ms |
4464 KB |
Partially correct |
4 |
Partially correct |
56 ms |
4924 KB |
Partially correct |
5 |
Partially correct |
50 ms |
5432 KB |
Partially correct |
6 |
Partially correct |
62 ms |
4932 KB |
Partially correct |
7 |
Partially correct |
59 ms |
4920 KB |
Partially correct |
8 |
Partially correct |
63 ms |
4668 KB |
Partially correct |
9 |
Partially correct |
59 ms |
4448 KB |
Partially correct |
10 |
Partially correct |
80 ms |
5160 KB |
Partially correct |
11 |
Partially correct |
64 ms |
4920 KB |
Partially correct |
12 |
Partially correct |
67 ms |
4696 KB |
Partially correct |
13 |
Incorrect |
133 ms |
4912 KB |
Wrong Answer [6] |
14 |
Halted |
0 ms |
0 KB |
- |