#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base :: sync_with_stdio(0);
cin.tie(0) , cout.tie(0);
int n;
cin >> n;
assert(n <= 300);
vector<long long> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
sort(a.begin() , a.end());
if (n == 2) {
cout << 1 << '\n' << a[0] << '\n';
cout << 1 << '\n' << a[1] << '\n';
return 0;
}
auto run = [&](int x , int y) {
int d1 = a[y] - a[x] , p1 = a[y];
vector<int> seq1 , seq2;
seq1.push_back(a[x]);
seq1.push_back(a[y]);
for (int i = 0; i < n; i++) {
if (i == x || i == y) {
continue;
}
if (a[i] - p1 == d1) {
seq1.push_back(a[i]);
p1 = a[i];
} else {
seq2.push_back(a[i]);
}
}
bool good = true;
if ((int)seq2.size() >= 2) {
for (int i = 1; i < (int)seq2.size() && good; i++) {
if (seq2[1] - seq2[0] != seq2[i] - seq2[i - 1]) {
good = false;
}
}
}
if (!good) {
//try to make good
multiset<int> q1 , q2;
for (int num : seq1) {
q1.insert(num);
}
int d2 = seq2[1] - seq2[0];
for (int num : seq2) {
q2.insert(num);
}
good = true;
for (int num : q2) {
if (num == *prev(q2.end())) {
continue;
}
if (q2.count(num + d2) == 0) {
auto it = q1.find(num + d2);
if (it == prev(q1.end())) {
q2.insert(*it);
q1.erase(it);
} else {
good = false;
}
}
}
if (good) {
cout << (int)q1.size() << '\n';
for (int num : q1) {
cout << num << " ";
}
cout << '\n';
cout << (int)q2.size() << '\n';
for (int num : q2) {
cout << num << " ";
}
cout << '\n';
exit(0);
}
}
if (good) {
if (seq2.empty()) {
seq2.push_back(seq1.back());
seq1.pop_back();
}
cout << (int)seq1.size() << '\n';
for (int num : seq1) {
cout << num << " ";
}
cout << '\n';
cout << (int)seq2.size() << '\n';
for (int num : seq2) {
cout << num << " ";
}
cout << '\n';
exit(0);
}
};
run(0 , 1);
run(0 , 2);
run(1 , 2);
cout << -1 << '\n';
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
380 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
252 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
380 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
252 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
3 ms |
632 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
380 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
252 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |