#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 _32bB6rn ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
using namespace std;
typedef long long ll;
typedef long double ld;
inline int read(){
int x;
cin>>x;
return x;
}
inline void print(int x){
cout<<x<<" ";
}
inline void println(int x){
cout<<x<<"\n";
}
using pii=pair<int,int>;
using vi=vector<int>;
using dq=deque<int>;
int main(){
_32bB6rn;
int n;
cin>>n;
vi a(n);
rep(i,n) cin>>a[i];
sort(all(a));
vec(vi) wata(2,vi(n));
wata[0][0]=wata[0][1]=1;
crep(i,2,n){
if(a[i]-a[i-1]!=a[i-1]-a[i-2]){
break;
}
wata[0][i]=1;
}
wata[1][n-1]=wata[1][n-2]=1;
drep(i,n-2){
if(a[i+1]-a[i]!=a[i+2]-a[i+1]){
break;
}
wata[1][i]=1;
}
auto out=[](dq up,dq dw){
vec(dq) cand;
cand.pb(up);
cand.pb(dw);
rep(t,2){
dq rbt=cand[t];
if(!sz(rbt))
return;
crep(i,2,sz(rbt)){
if(rbt[i]-rbt[i-1]!=rbt[i-1]-rbt[i-2]){
return;
}
}
}
rep(t,2){
dq rbt=cand[t];
println(sz(rbt));
for(auto x : rbt){
print(x);
}
cout<<"\n";
}
exit(0);
};
auto affine=[&](int id1,int id2){
vi usd(n,0);
usd[id1]=usd[id2]=1;
dq up,dw;
up.pb(a[id1]);
up.pb(a[id2]);
int diff=a[id2]-a[id1];
crep(i,id1,n){
if(usd[i]) continue;
if(wata[1][i]){
crep(j,i,n) dw.pb(a[j]);
break;
}
int x=a[i];
if(x-up.back()==diff){
up.pb(x);
}else{
dw.pb(x);
}
}
drep(i,id1){
if(usd[i]) continue;
if(wata[0][i]){
drep(j,i) dw.push_front(a[j]);
break;
}
int x=a[i];
if(up.front()-x==diff){
up.push_front(x);
}else{
dw.push_front(x);
}
}
out(up,dw);
};
rep(i,n){
if(i+1<n){
// if(a[i+1]-a[i]!=a[i+2]-a[i+1]){
affine(i,i+1);
// affine(i,i+2);
// affine(i+1,i+2);
// break;
// }
}
}
dq up,dw;
rep(_,2){
for(int i=_;i<n;i+=2){
if(_==0) up.pb(a[i]);
else dw.pb(a[i]);
}
}
out(up,dw);
puts("-1");
//
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
31 ms |
4220 KB |
Output is correct |
2 |
Correct |
27 ms |
5180 KB |
Output is correct |
3 |
Correct |
26 ms |
5252 KB |
Output is correct |
4 |
Correct |
31 ms |
5304 KB |
Output is correct |
5 |
Execution timed out |
1068 ms |
4428 KB |
Time limit exceeded |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |