#include <bits/stdc++.h>
#include "monster.h"
using namespace std;
#define endl '\n'
#define st first
#define nd second
#define pb push_back
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define ll long long
ll mod=1000000007;
int inf=1000000007;
ll infl=1000000000000000007;
/*
const int N=1007;
int p[N];
bool Query(int a, int b)
{
if(abs(p[a]-p[b])==1) return p[a]<p[b];
else return p[a]>p[b];
}*/
bool ok[1007];
vector<int>Sort(vector<int>V)
{
if(sz(V)<=1) return V;
int m=sz(V)/2;
vector<int>L,R,A;
for(int i=0;i<m;i++) L.pb(V[i]);
for(int i=m;i<sz(V);i++) R.pb(V[i]);
L=Sort(L);
R=Sort(R);
int l=0,r=0;
for(int i=0;i<sz(V);i++)
{
if(l==sz(L))
{
A.pb(R[r]);
r++;
}
else if(r==sz(R))
{
A.pb(L[l]);
l++;
}
else if(Query(L[l],R[r]))
{
A.pb(R[r]);
r++;
}
else
{
A.pb(L[l]);
l++;
}
}
return A;
}
vector<int>Solve(int n)
{
memset(ok,0,sizeof ok);
vector<int>V(n);
for(int i=0;i<n;i++) V[i]=i;
random_shuffle(all(V));
V=Sort(V);
for(int b=0;b<4;b++)
{
if(b+4<n&&Query(V[b],V[b+2])&&Query(V[b+1],V[b+3])&&Query(V[b+2],V[b+4]))
{
ok[b]=1;
ok[b+1]=1;
ok[b+2]=1;
ok[b+3]=1;
ok[b+4]=1;
int l=b+5;
for(int j=b+3;j+2<n;j++)
{
if(!Query(V[j],V[j+2])) break;
ok[j+2]=1;
l++;
}
reverse(V.begin()+b,V.begin()+l);
}
}
int A=-1,B=-1;
for(int i=0;i<min(n,10);i++)
{
int c=0;
for(int j=0;j<min(n,10);j++) if(i!=j) c+=Query(V[i],V[j]);
if(c==1)
{
if(A==-1) A=i;
else B=i;
}
}
if(Query(V[A],V[B])) reverse(V.begin(),V.begin()+A+1);
else reverse(V.begin(),V.begin()+B+1);
for(int i=1;i<n;i++)
{
if(ok[i]) continue;
for(int j=i;j<n;j++)
{
ok[j]=1;
if(Query(V[i-1],V[j]))
{
reverse(V.begin()+i,V.begin()+j+1);
break;
}
}
}
vector<int>ans(n,0);
for(int i=0;i<n;i++) ans[V[i]]=i;
return ans;
}
/*
void Case1(int n)
{
for(int i=0;i<n;i++) cin>>p[i];
vector<int>V=Solve(n);
for(auto x:V) cout<<x<<" ";
}
bool Case(int n)
{
for(int i=0;i<n;i++) p[i]=i;
random_shuffle(p,p+n);
vector<int>V=Solve(n);
bool is=1;
for(int i=0;i<n;i++) if(p[i]!=V[i]) is=0;
if(!is)
{
for(auto x:V) cout<<x<<" ";
cout<<endl;
}
return is;
}
int main()
{
int n;
cin>>n;
// Case1(n);
while(true)
{
if(!Case(n)) break;
}
for(int i=0;i<n;i++) cout<<p[i]<<" ";
cout<<endl;
return 0;
}
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
208 KB |
Output is correct |
2 |
Correct |
1 ms |
208 KB |
Output is correct |
3 |
Correct |
1 ms |
208 KB |
Output is correct |
4 |
Correct |
1 ms |
208 KB |
Output is correct |
5 |
Correct |
1 ms |
208 KB |
Output is correct |
6 |
Correct |
1 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 |
1 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 |
10 ms |
304 KB |
Output is correct |
17 |
Correct |
14 ms |
288 KB |
Output is correct |
18 |
Correct |
11 ms |
208 KB |
Output is correct |
19 |
Correct |
11 ms |
304 KB |
Output is correct |
20 |
Correct |
13 ms |
208 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 |
12 ms |
284 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 |
12 ms |
208 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
208 KB |
Output is correct |
2 |
Correct |
1 ms |
208 KB |
Output is correct |
3 |
Correct |
1 ms |
208 KB |
Output is correct |
4 |
Correct |
1 ms |
208 KB |
Output is correct |
5 |
Correct |
1 ms |
208 KB |
Output is correct |
6 |
Correct |
1 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 |
1 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 |
10 ms |
304 KB |
Output is correct |
17 |
Correct |
14 ms |
288 KB |
Output is correct |
18 |
Correct |
11 ms |
208 KB |
Output is correct |
19 |
Correct |
11 ms |
304 KB |
Output is correct |
20 |
Correct |
13 ms |
208 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 |
12 ms |
284 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 |
12 ms |
208 KB |
Output is correct |
33 |
Correct |
83 ms |
300 KB |
Output is correct |
34 |
Correct |
66 ms |
304 KB |
Output is correct |
35 |
Correct |
60 ms |
316 KB |
Output is correct |
36 |
Correct |
82 ms |
308 KB |
Output is correct |
37 |
Correct |
79 ms |
208 KB |
Output is correct |
38 |
Correct |
60 ms |
304 KB |
Output is correct |
39 |
Correct |
85 ms |
300 KB |
Output is correct |
40 |
Correct |
52 ms |
320 KB |
Output is correct |
41 |
Correct |
58 ms |
304 KB |
Output is correct |
42 |
Correct |
84 ms |
304 KB |
Output is correct |
43 |
Correct |
94 ms |
304 KB |
Output is correct |
44 |
Correct |
80 ms |
300 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
60 ms |
208 KB |
Output is correct |
2 |
Correct |
70 ms |
208 KB |
Output is correct |
3 |
Correct |
94 ms |
304 KB |
Output is correct |
4 |
Correct |
58 ms |
208 KB |
Output is correct |
5 |
Correct |
79 ms |
312 KB |
Output is correct |
6 |
Correct |
38 ms |
324 KB |
Output is correct |
7 |
Correct |
44 ms |
324 KB |
Output is correct |
8 |
Correct |
84 ms |
208 KB |
Output is correct |
9 |
Correct |
84 ms |
208 KB |
Output is correct |
10 |
Correct |
69 ms |
324 KB |
Output is correct |
11 |
Correct |
70 ms |
300 KB |
Output is correct |
12 |
Correct |
82 ms |
208 KB |
Output is correct |
13 |
Correct |
70 ms |
424 KB |
Output is correct |
14 |
Correct |
75 ms |
208 KB |
Output is correct |
15 |
Correct |
33 ms |
308 KB |
Output is correct |
16 |
Correct |
44 ms |
208 KB |
Output is correct |
17 |
Correct |
72 ms |
208 KB |
Output is correct |
18 |
Correct |
40 ms |
320 KB |
Output is correct |