#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define sz(a) (int)a.size()
#define all(a) a.begin(),a.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define crep(i,x,n) for(int i=x;i<n;i++)
#define drep(i,n) for(int i=n-1;i>=0;i--)
#define vec(...) vector<__VA_ARGS__>
#define _3qplfh5 ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
using namespace std;
typedef long long ll;
typedef long double ld;
using pii=pair<int,int>;
using vi=vector<int>;
using vll=vector<long long>;
int main(){
_3qplfh5;
int n;
cin>>n;
vi a(n);
rep(i,n){
cin>>a[i];
}
sort(all(a));
vi wata(n,-1);
wata[n-1]=-1;
wata[n-2]=-1;
drep(i,n-2){
if(a[i+1]-a[i]!=a[i+2]-a[i+1]){
break;
}
wata[i]=a[i+1]-a[i];
}
// rep(i,n){
// cout<<wata[i]<<" ";
// }
// cout<<"\n";
auto g=[&](vi up,vi dw){
vec(vi) cands;
cands.pb(up);
cands.pb(dw);
int now=0;
rep(t,2){
if(!sz(cands[t]))
return;
now+=sz(cands[t]);
}
if(now!=n){
return;
}
rep(t,2){
crep(i,2,sz(cands[t])){
if(cands[t][i]-cands[t][i-1]!=cands[t][i-1]-cands[t][i-2])
return;
}
}
rep(t,2){
cout<<sz(cands[t])<<"\n";
for(auto x : cands[t]){
cout<<x<<" ";
}
cout<<"\n";
}
exit(0);
};
auto f=[&](int id,int id2){
vi up,dw;
up.pb(a[id]);
up.pb(a[id2]);
int diff=a[id2]-a[id];
rep(i,n){
if(i==id or i==id2){
continue;
}
if(sz(dw)>=3){
if(dw[sz(dw)-1]-dw[sz(dw)-2]!=dw[sz(dw)-2]-dw[sz(dw)-3]){
return;
}
}
int x=a[i];
if(x-up.back()!=diff){
dw.pb(x);
}else{
if(i>=n-3 or wata[i+1]!=-1){
crep(j,i,n){
dw.pb(a[j]);
}
g(up,dw);
crep(j,i,n){
dw.pop_back();
}
}
up.pb(x);
}
}
g(up,dw);
};
if(n!=2){
f(0,1);
f(0,2);
f(1,2);
}else{
g({a[0]},{a[1]});
}
cout<<"-1\n";
//
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
0 ms |
204 KB |
Output is correct |
11 |
Correct |
0 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
0 ms |
204 KB |
Output is correct |
14 |
Correct |
0 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
0 ms |
204 KB |
Output is correct |
11 |
Correct |
0 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
0 ms |
204 KB |
Output is correct |
14 |
Correct |
0 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
0 ms |
204 KB |
Output is correct |
17 |
Correct |
0 ms |
204 KB |
Output is correct |
18 |
Correct |
0 ms |
204 KB |
Output is correct |
19 |
Correct |
0 ms |
204 KB |
Output is correct |
20 |
Correct |
0 ms |
204 KB |
Output is correct |
21 |
Correct |
0 ms |
204 KB |
Output is correct |
22 |
Correct |
0 ms |
204 KB |
Output is correct |
23 |
Correct |
0 ms |
204 KB |
Output is correct |
24 |
Correct |
0 ms |
204 KB |
Output is correct |
25 |
Correct |
0 ms |
204 KB |
Output is correct |
26 |
Correct |
0 ms |
204 KB |
Output is correct |
27 |
Correct |
0 ms |
204 KB |
Output is correct |
28 |
Correct |
0 ms |
204 KB |
Output is correct |
29 |
Correct |
0 ms |
204 KB |
Output is correct |
30 |
Correct |
0 ms |
256 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
24 ms |
3208 KB |
Output is correct |
2 |
Correct |
24 ms |
3260 KB |
Output is correct |
3 |
Correct |
24 ms |
3200 KB |
Output is correct |
4 |
Correct |
25 ms |
3256 KB |
Output is correct |
5 |
Correct |
25 ms |
3168 KB |
Output is correct |
6 |
Correct |
24 ms |
3260 KB |
Output is correct |
7 |
Correct |
30 ms |
3164 KB |
Output is correct |
8 |
Correct |
24 ms |
3256 KB |
Output is correct |
9 |
Correct |
22 ms |
2876 KB |
Output is correct |
10 |
Correct |
25 ms |
3252 KB |
Output is correct |
11 |
Correct |
18 ms |
3412 KB |
Output is correct |
12 |
Correct |
0 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
0 ms |
204 KB |
Output is correct |
11 |
Correct |
0 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
0 ms |
204 KB |
Output is correct |
14 |
Correct |
0 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
0 ms |
204 KB |
Output is correct |
17 |
Correct |
0 ms |
204 KB |
Output is correct |
18 |
Correct |
0 ms |
204 KB |
Output is correct |
19 |
Correct |
0 ms |
204 KB |
Output is correct |
20 |
Correct |
0 ms |
204 KB |
Output is correct |
21 |
Correct |
0 ms |
204 KB |
Output is correct |
22 |
Correct |
0 ms |
204 KB |
Output is correct |
23 |
Correct |
0 ms |
204 KB |
Output is correct |
24 |
Correct |
0 ms |
204 KB |
Output is correct |
25 |
Correct |
0 ms |
204 KB |
Output is correct |
26 |
Correct |
0 ms |
204 KB |
Output is correct |
27 |
Correct |
0 ms |
204 KB |
Output is correct |
28 |
Correct |
0 ms |
204 KB |
Output is correct |
29 |
Correct |
0 ms |
204 KB |
Output is correct |
30 |
Correct |
0 ms |
256 KB |
Output is correct |
31 |
Correct |
24 ms |
3208 KB |
Output is correct |
32 |
Correct |
24 ms |
3260 KB |
Output is correct |
33 |
Correct |
24 ms |
3200 KB |
Output is correct |
34 |
Correct |
25 ms |
3256 KB |
Output is correct |
35 |
Correct |
25 ms |
3168 KB |
Output is correct |
36 |
Correct |
24 ms |
3260 KB |
Output is correct |
37 |
Correct |
30 ms |
3164 KB |
Output is correct |
38 |
Correct |
24 ms |
3256 KB |
Output is correct |
39 |
Correct |
22 ms |
2876 KB |
Output is correct |
40 |
Correct |
25 ms |
3252 KB |
Output is correct |
41 |
Correct |
18 ms |
3412 KB |
Output is correct |
42 |
Correct |
0 ms |
204 KB |
Output is correct |
43 |
Correct |
23 ms |
3248 KB |
Output is correct |
44 |
Correct |
16 ms |
1484 KB |
Output is correct |
45 |
Correct |
22 ms |
3060 KB |
Output is correct |
46 |
Correct |
24 ms |
3248 KB |
Output is correct |
47 |
Correct |
16 ms |
1488 KB |
Output is correct |
48 |
Correct |
22 ms |
2932 KB |
Output is correct |
49 |
Correct |
24 ms |
3188 KB |
Output is correct |
50 |
Correct |
16 ms |
1356 KB |
Output is correct |
51 |
Correct |
23 ms |
3060 KB |
Output is correct |
52 |
Correct |
25 ms |
3216 KB |
Output is correct |
53 |
Correct |
17 ms |
1524 KB |
Output is correct |
54 |
Correct |
24 ms |
2932 KB |
Output is correct |
55 |
Correct |
24 ms |
3196 KB |
Output is correct |
56 |
Correct |
19 ms |
3256 KB |
Output is correct |
57 |
Correct |
21 ms |
3412 KB |
Output is correct |
58 |
Correct |
0 ms |
204 KB |
Output is correct |