#include "monster.h"
#include <bits/stdc++.h>
using namespace std;
#define sf scanf
#define pf printf
#define fi first
#define se second
#define pb emplace_back
#define sz(x) (int)x.size()
#define mnto(x,y) x=min(x,(__typeof__(x))y)
#define mxto(x,y) x=max(x,(__typeof__(x))y)
#define INF 1023456789
#define LINF 1023456789123456789
#define all(x) x.begin(), x.end()
typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef pair<ll, ll> pll;
typedef tuple<int, int, int> iii;
typedef tuple<int, int, int, int> iiii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<pll> vll;
namespace{
vector<int> a,t,s,ans;
vector<ii> p;
void mergesort(int l,int r){
if(l==r)return;
int m=(l+r)/2;
mergesort(l,m);
mergesort(m+1,r);
t.clear();
int cl=l,cr=m+1;
while(cl<=m||cr<=r){
if(cl>m||(cr<=r&&Query(a[cl],a[cr])))t.pb(a[cr++]);
else t.pb(a[cl++]);
}
for(int i=l;i<=r;++i)a[i]=t[i-l];
t.clear();
}
void small(int n){//brute force the first n elements
for(int i=0;i<n;++i){
int cnt=0;
for(int j=0;j<n;++j){
if(j==i)continue;
cnt+=Query(s[i],s[j]);
}
p.pb(cnt,s[i]);
}
sort(all(p));
if(Query(p[1].se,p[0].se))swap(p[1],p[0]);
if(Query(p[n-1].se,p[n-2].se))swap(p[n-2],p[n-1]);
for(int i=0;i<n;++i)s[i]=p[i].se;
}
}
vector<int> Solve(int n){
for(int i=0;i<n;++i)a.pb(i);
mergesort(0,n-1);
for(int i=0;i<min(n,10);++i)s.pb(a[i]);
small(min(n,10));
a.erase(find(all(a),s[0]));
a.insert(a.begin(),s[0]);
ans.resize(n);
int cur=0;
for(int i=cur+1;i<n;++i){
if(Query(a[cur],a[i])){
reverse(a.begin()+cur+1,a.begin()+i+1);
cur=i;
}
}
for(int i=0;i<n;++i)ans[a[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 |
1 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 |
2 ms |
200 KB |
Output is correct |
15 |
Correct |
1 ms |
200 KB |
Output is correct |
16 |
Correct |
16 ms |
200 KB |
Output is correct |
17 |
Correct |
20 ms |
200 KB |
Output is correct |
18 |
Correct |
14 ms |
200 KB |
Output is correct |
19 |
Correct |
14 ms |
200 KB |
Output is correct |
20 |
Correct |
19 ms |
200 KB |
Output is correct |
21 |
Correct |
2 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 |
12 ms |
200 KB |
Output is correct |
27 |
Correct |
1 ms |
200 KB |
Output is correct |
28 |
Correct |
1 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 |
2 ms |
200 KB |
Output is correct |
32 |
Correct |
9 ms |
200 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 |
1 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 |
2 ms |
200 KB |
Output is correct |
15 |
Correct |
1 ms |
200 KB |
Output is correct |
16 |
Correct |
16 ms |
200 KB |
Output is correct |
17 |
Correct |
20 ms |
200 KB |
Output is correct |
18 |
Correct |
14 ms |
200 KB |
Output is correct |
19 |
Correct |
14 ms |
200 KB |
Output is correct |
20 |
Correct |
19 ms |
200 KB |
Output is correct |
21 |
Correct |
2 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 |
12 ms |
200 KB |
Output is correct |
27 |
Correct |
1 ms |
200 KB |
Output is correct |
28 |
Correct |
1 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 |
2 ms |
200 KB |
Output is correct |
32 |
Correct |
9 ms |
200 KB |
Output is correct |
33 |
Correct |
109 ms |
280 KB |
Output is correct |
34 |
Correct |
89 ms |
200 KB |
Output is correct |
35 |
Correct |
107 ms |
320 KB |
Output is correct |
36 |
Correct |
108 ms |
280 KB |
Output is correct |
37 |
Correct |
70 ms |
280 KB |
Output is correct |
38 |
Correct |
103 ms |
288 KB |
Output is correct |
39 |
Correct |
85 ms |
200 KB |
Output is correct |
40 |
Correct |
109 ms |
284 KB |
Output is correct |
41 |
Correct |
84 ms |
284 KB |
Output is correct |
42 |
Correct |
112 ms |
280 KB |
Output is correct |
43 |
Correct |
63 ms |
276 KB |
Output is correct |
44 |
Correct |
51 ms |
276 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
67 ms |
320 KB |
Output is correct |
2 |
Correct |
136 ms |
280 KB |
Output is correct |
3 |
Correct |
117 ms |
276 KB |
Output is correct |
4 |
Correct |
97 ms |
320 KB |
Output is correct |
5 |
Correct |
83 ms |
292 KB |
Output is correct |
6 |
Correct |
60 ms |
284 KB |
Output is correct |
7 |
Correct |
93 ms |
288 KB |
Output is correct |
8 |
Correct |
123 ms |
320 KB |
Output is correct |
9 |
Correct |
93 ms |
280 KB |
Output is correct |
10 |
Correct |
98 ms |
320 KB |
Output is correct |
11 |
Correct |
76 ms |
200 KB |
Output is correct |
12 |
Correct |
115 ms |
200 KB |
Output is correct |
13 |
Correct |
84 ms |
276 KB |
Output is correct |
14 |
Correct |
80 ms |
200 KB |
Output is correct |
15 |
Correct |
55 ms |
288 KB |
Output is correct |
16 |
Correct |
83 ms |
284 KB |
Output is correct |
17 |
Correct |
76 ms |
292 KB |
Output is correct |
18 |
Correct |
54 ms |
200 KB |
Output is correct |