Submission #498228

# Submission time Handle Problem Language Result Execution time Memory
498228 2021-12-24T16:00:35 Z inksamurai Drvca (COCI19_drvca) C++17
0 / 110
21 ms 3516 KB
#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+2<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;
}
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 21 ms 3516 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -