#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());
vector<int>v0, v1;
v0.push_back(a[0]);
int p = 1;
while(max(v0.size(), v1.size())<2) {
int dif = a[p] - v0[0];
int last = a[p];
vector<int>v3 = v1;
for(int i=p+1; i<N; ++i) {
if(a[i]-last == dif) last = a[i];
else v3.push_back(a[i]);
}
bool evenGap = true;
for(int i=2; i<v3.size(); ++i) {
evenGap &= v3[i]-v3[i-1]==v3[i-1]-v3[i-2];
}
if(evenGap) {
v0.push_back(a[p++]);
break;
} else {
v1.push_back(a[p++]);
}
}
if(v0.size()==1) swap(v0, v1);
int last = v0[1], dif = v0[1] - v0[0];
for(int i=p; i<N; ++i) {
if(dif + last == a[i]) v0.push_back(a[i]), last = a[i];
else v1.push_back(a[i]);
}
bool evenGap = true;
for(int i=2; i<v1.size(); ++i) {
evenGap &= v1[i]-v1[i-1]==v1[i-1]-v1[i-2];
}
if(v1.empty()) v1.push_back(v0.back()), v0.pop_back();
if(evenGap) {
cout << v0.size() << '\n';
for(auto it : v0) cout << it << ' ';
cout << '\n';
cout << v1.size() << '\n';
for(auto it : v1) cout << it << ' ';
cout << '\n';
} else 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:31:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
31 | for(int i=2; i<v3.size(); ++i) {
| ~^~~~~~~~~~
drvca.cpp:48:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
48 | for(int i=2; i<v1.size(); ++i) {
| ~^~~~~~~~~~
# |
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 |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 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 |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
10 |
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 |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 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 |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
36 ms |
2448 KB |
Output is correct |
2 |
Correct |
32 ms |
2308 KB |
Output is correct |
3 |
Correct |
32 ms |
2436 KB |
Output is correct |
4 |
Correct |
33 ms |
2304 KB |
Output is correct |
5 |
Correct |
38 ms |
2452 KB |
Output is correct |
6 |
Correct |
38 ms |
2304 KB |
Output is correct |
7 |
Correct |
32 ms |
2432 KB |
Output is correct |
8 |
Correct |
33 ms |
2396 KB |
Output is correct |
9 |
Incorrect |
20 ms |
1436 KB |
Output isn't correct |
10 |
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 |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 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 |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |