#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define debug(x) cerr << '[' << (#x) << "] = " << x << '\n';
template<class T> using ordered_set = tree<T, null_type , less<T> , rb_tree_tag , tree_order_statistics_node_update> ;
void PlayGround() {
int N; cin >> N;
vector<int>a(N);
for(int i=0; i<N; ++i) cin >> a[i];
sort(a.begin(), a.end());
if(N < 4) {
cout << 1 << '\n' << a[0] << '\n' << N-1 << '\n';
for(int i=1; i<N; ++i) cout << a[i] << ' ';
cout << '\n';
return;
}
auto print = [] (vector<int>&x, vector<int>&y) {
cout << x.size() << '\n';
for(auto it : x) cout << it << ' ';
cout << '\n';
cout << y.size() << '\n';
for(auto it : y) cout << it << ' ';
cout << "\n";
};
auto check = [] (multiset<int>& ms) {
if(ms.size()<3) return true;
int dif = *(next(ms.begin(), 1)) - *ms.begin();
int last = *ms.begin() - dif;
bool ret = true;
for(auto it : ms) {
ret &= it==last+dif;
last = it;
}
return ret;
};
vector<int>b = {0, 1, 2};
do {
vector<int>x = {a[b[0]], a[b[1]]};
if(x[0]>x[1]) swap(x[0], x[1]);
int dif = x[1] - x[0];
multiset<int>ms;
ms.insert(a[b[2]]);
for(int i=3; i<N; ++i) {
if(a[i]-x.back()==dif && x.size()<N/2) x.push_back(a[i]);
else ms.insert(a[i]);
}
// if(ms.empty()) {
// vector<int>y = {x.back()};
// x.pop_back();
// print(x, y);
// return;
// }
// for(int i=x.size(); i>0; --i) {
// if(i<x.size()) ms.insert(x[i]);
// if(check(ms)) {
// vector<int>y;
// for(auto it : ms) y.push_back(it);
// x.resize(i);
// print(x, y);
// return;
// }
// }
if(check(ms)) {
vector<int>y;
for(auto it : ms) y.push_back(it);
print(x, y);
return;
}
} while(next_permutation(b.begin(), b.end()));
vector<int>x = {a[0], a[1], a[2]}, y;
if(x[2]-x[1]!=x[1]-x[0]) {
cout << -1 << '\n';
return;
}
multiset<int>ms;
for(int i=3; i<N; ++i) {
if(a[i]-x.back()==x[1]-x[0] && x.size()<N/2) x.push_back(a[i]);
else ms.insert(a[i]);
}
// if(ms.empty()) {
// vector<int>y = {x.back()};
// x.pop_back();
// print(x, y);
// return;
// }
// for(int i=x.size(); i>0; --i) {
// if(i<x.size()) ms.insert(x[i]);
// if(check(ms)) {
// vector<int>y;
// for(auto it : ms) y.push_back(it);
// x.resize(i);
// print(x, y);
// return;
// }
// }
if(check(ms)) {
vector<int>y;
for(auto it : ms) y.push_back(it);
print(x, y);
return;
}
cout << -1 << '\n';
#ifndef ONLINE_JUDGE
cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
// #ifndef ONLINE_JUDGE
// freopen("input.txt", "r", stdin);
//#endif
PlayGround();
return 0;
}
Compilation message
drvca.cpp: In function 'void PlayGround()':
drvca.cpp:54:46: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
54 | if(a[i]-x.back()==dif && x.size()<N/2) x.push_back(a[i]);
| ~~~~~~~~^~~~
drvca.cpp:88:48: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
88 | if(a[i]-x.back()==x[1]-x[0] && x.size()<N/2) x.push_back(a[i]);
| ~~~~~~~~^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
146 ms |
6292 KB |
Output is correct |
2 |
Correct |
152 ms |
6276 KB |
Output is correct |
3 |
Correct |
149 ms |
6344 KB |
Output is correct |
4 |
Correct |
144 ms |
6344 KB |
Output is correct |
5 |
Correct |
143 ms |
6288 KB |
Output is correct |
6 |
Correct |
151 ms |
6412 KB |
Output is correct |
7 |
Correct |
152 ms |
6336 KB |
Output is correct |
8 |
Correct |
142 ms |
6336 KB |
Output is correct |
9 |
Correct |
141 ms |
6084 KB |
Output is correct |
10 |
Correct |
145 ms |
7268 KB |
Output is correct |
11 |
Correct |
37 ms |
5444 KB |
Output is correct |
12 |
Correct |
0 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |