Submission #498245

# Submission time Handle Problem Language Result Execution time Memory
498245 2021-12-24T17:02:41 Z inksamurai Drvca (COCI19_drvca) C++17
0 / 110
1000 ms 9608 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";
}

inline void put(string s){
	cout<<s<<"\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));
 	
 	// rep(i,n){
 	// 	print(wata[1][i]);
 	// }
 	// put("");

	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);
			}
			put("");
		}
		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];
		rep(t,3){
			crep(i,id1,n){
				if(usd[i]) continue;
				int x=a[i];
				if(x-up.back()==diff){
					if(sz(dw) and x-dw.back()!=diff){
						up.pb(x);
					}else{
						crep(j,i,n){
							if(t==0) up.pb(x);
							else dw.pb(x);
						}
						break;
					}
				}else{
					dw.pb(x);
				}
			}
			drep(i,id1){
				if(usd[i]) continue;
				int x=a[i];
				if(up.front()-x==diff){
					if(sz(dw) and dw.front()-x!=diff){
						up.push_front(x);
					}else{
						crep(j,i,n){
							if(t==2) up.push_front(x);
							else dw.push_front(x);
						}
						break;
					}
				}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;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Incorrect 0 ms 204 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Incorrect 0 ms 204 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 453 ms 9608 KB Output is correct
2 Execution timed out 1077 ms 9452 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Incorrect 0 ms 204 KB Output isn't correct
8 Halted 0 ms 0 KB -