#include "monster.h"
#include <bits/stdc++.h>
using namespace std;
vector<int> Solve(int n){
mt19937 rng(777);
map<pair<int,int>,bool> memo;
auto query=[&](int x,int y){
if(memo.count({x,y}))return memo[{x,y}];
bool res=Query(x,y);
memo[{x,y}]=res;
memo[{y,x}]=!res;
return res;
};
vector<int> a(n),b(n);
function<void(int,int)> msort=[&](int l,int r){
if(l==r)return;
shuffle(a.begin()+l,a.begin()+r+1,rng);
int m=(l+r)/2;
msort(l,m);
msort(m+1,r);
for(int i=l,j=m+1,p=l;p<=r;p++){
if(j>r||(i<=m&&!query(a[i],a[j]))){
b[p]=a[i++];
}else{
b[p]=a[j++];
}
}
for(int i=l;i<=r;i++)a[i]=b[i];
};
iota(a.begin(),a.end(),0);
msort(0,n-1);
auto check=[&](int x){
int cnt=0;
for(int i=0;i<n;i++){
if(i==x)continue;
if(query(a[x],a[i])){
cnt++;
if(cnt>1){
return false;
}
}
}
return true;
};
bool ok0=check(0),ok1=check(1);
int st=-1;
if(ok0){
if(ok1){
for(int i=2;i<n;i++){
bool v0=query(a[i],a[0]);
bool v1=query(a[i],a[1]);
assert(v0||v1);
if(v0^v1){
st=v1;
break;
}
}
}else{
st=0;
}
}
if(st==-1){
st=2;
while((query(a[st-1],a[st])||query(a[st],a[0]))){
st++;
assert(st<n);
}
}
reverse(a.begin(),a.begin()+st+1);
for(int i=st+1;i<n;i++){
int j=i;
while(!query(a[i-1],a[j])){
j++;
assert(j<n);
}
reverse(a.begin()+i,a.begin()+j+1);
i=j;
}
vector<int> ans(n);
for(int i=0;i<n;i++)ans[a[i]]=i;
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 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 |
344 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 |
384 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 |
9 ms |
600 KB |
Output is correct |
17 |
Correct |
8 ms |
520 KB |
Output is correct |
18 |
Correct |
14 ms |
600 KB |
Output is correct |
19 |
Correct |
9 ms |
856 KB |
Output is correct |
20 |
Correct |
9 ms |
792 KB |
Output is correct |
21 |
Correct |
1 ms |
344 KB |
Output is correct |
22 |
Correct |
0 ms |
344 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 |
8 ms |
600 KB |
Output is correct |
27 |
Correct |
0 ms |
344 KB |
Output is correct |
28 |
Correct |
0 ms |
344 KB |
Output is correct |
29 |
Correct |
1 ms |
344 KB |
Output is correct |
30 |
Correct |
0 ms |
344 KB |
Output is correct |
31 |
Correct |
1 ms |
344 KB |
Output is correct |
32 |
Correct |
7 ms |
600 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 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 |
344 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 |
384 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 |
9 ms |
600 KB |
Output is correct |
17 |
Correct |
8 ms |
520 KB |
Output is correct |
18 |
Correct |
14 ms |
600 KB |
Output is correct |
19 |
Correct |
9 ms |
856 KB |
Output is correct |
20 |
Correct |
9 ms |
792 KB |
Output is correct |
21 |
Correct |
1 ms |
344 KB |
Output is correct |
22 |
Correct |
0 ms |
344 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 |
8 ms |
600 KB |
Output is correct |
27 |
Correct |
0 ms |
344 KB |
Output is correct |
28 |
Correct |
0 ms |
344 KB |
Output is correct |
29 |
Correct |
1 ms |
344 KB |
Output is correct |
30 |
Correct |
0 ms |
344 KB |
Output is correct |
31 |
Correct |
1 ms |
344 KB |
Output is correct |
32 |
Correct |
7 ms |
600 KB |
Output is correct |
33 |
Correct |
66 ms |
1916 KB |
Output is correct |
34 |
Correct |
53 ms |
1868 KB |
Output is correct |
35 |
Correct |
60 ms |
1616 KB |
Output is correct |
36 |
Correct |
76 ms |
1820 KB |
Output is correct |
37 |
Correct |
77 ms |
1616 KB |
Output is correct |
38 |
Correct |
60 ms |
1860 KB |
Output is correct |
39 |
Correct |
85 ms |
2204 KB |
Output is correct |
40 |
Correct |
60 ms |
1772 KB |
Output is correct |
41 |
Correct |
71 ms |
1848 KB |
Output is correct |
42 |
Correct |
65 ms |
1872 KB |
Output is correct |
43 |
Correct |
70 ms |
2040 KB |
Output is correct |
44 |
Correct |
79 ms |
1632 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Partially correct |
76 ms |
1792 KB |
Partially correct |
2 |
Partially correct |
79 ms |
2508 KB |
Partially correct |
3 |
Partially correct |
70 ms |
1688 KB |
Partially correct |
4 |
Partially correct |
75 ms |
1828 KB |
Partially correct |
5 |
Partially correct |
74 ms |
1708 KB |
Partially correct |
6 |
Correct |
60 ms |
1516 KB |
Output is correct |
7 |
Correct |
58 ms |
1592 KB |
Output is correct |
8 |
Partially correct |
77 ms |
2092 KB |
Partially correct |
9 |
Partially correct |
63 ms |
2420 KB |
Partially correct |
10 |
Partially correct |
60 ms |
1676 KB |
Partially correct |
11 |
Partially correct |
91 ms |
1696 KB |
Partially correct |
12 |
Partially correct |
67 ms |
2476 KB |
Partially correct |
13 |
Correct |
69 ms |
1400 KB |
Output is correct |
14 |
Correct |
61 ms |
1768 KB |
Output is correct |
15 |
Correct |
40 ms |
1364 KB |
Output is correct |
16 |
Correct |
44 ms |
1100 KB |
Output is correct |
17 |
Correct |
66 ms |
1732 KB |
Output is correct |
18 |
Correct |
44 ms |
1164 KB |
Output is correct |