//!yrt tsuj uoy srettam gnihton no emoc
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define pb push_back
#define mp make_pair
#define pii pair <int, int>
#define fast_io ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define F first
#define S second
const int maxn = 1e5 + 5;
int n, a[maxn], d[maxn];
bool mark[maxn];
void output(int c){
cout << c << endl;
for(int i = 0; i < n; i ++){
if(mark[i]){
cout << a[i] << " ";
}
}
cout << endl << n - c << endl;
for(int i = 0; i < n; i ++){
if(!mark[i]){
cout << a[i] << " ";
}
}
return;
}
bool solve(int x, int tar){
int t = -2, t2 = -2, last = -1;
int c = 2;
for(int i = 0; i < n; i ++){
// cout << x << " " << tar << " " << t << " " << t2 << " " << last << " " << c << endl;
if(mark[i]){
continue;
}
if(a[i] == t2){
t2 += t;
if(d[i] == t || d[i] == -2){
output(c);
return true;
}
}
else if(a[i] == tar){
tar += x;
mark[i] = true;
c ++;
}
else{
if(t == -2){
t ++;
last = a[i];
}
else if(t == -1){
t = a[i] - last;
t2 = a[i] + t;
if(d[i] == t || d[i] == -2){
output(c);
return true;
}
}
else if(a[i] != t2){
// cout << "why? " << i << endl;
return false;
}
else{
t2 += t;
if(d[i] == t || d[i] == -2){
output(c);
return true;
}
}
}
}
if(c == n){
cout << n - 1 << endl;
for(int i = 0; i < n - 1; i ++){
cout << a[i] << " ";
}
cout << endl << 1 << endl;
cout << a[n - 1];
return true;
}
output(c);
return true;
}
int main(){
fast_io;
cin >> n;
for(int i = 0; i < n; i ++){
cin >> a[i];
}
sort(a, a + n);
d[n - 2] = a[n - 1] - a[n - 2];
for(int i = n - 3; i >= 0; i --){
if(a[i] == a[i + 1] - d[i + 1]){
d[i] = d[i + 1];
}else{
d[i] = -1;
}
}
d[n - 1] = -2;
// cout << "d : ";
// for(int i = 0; i < n; i ++){
// cout << a[i] << " ";
// }
// cout << endl;
memset(mark, false, sizeof mark);
mark[0] = mark[1] = true;
if(solve(a[1] - a[0], a[1] + (a[1] - a[0]))){
return 0;
}
memset(mark, false, sizeof mark);
mark[0] = mark[2] = true;
if(solve(a[2] - a[0], a[2] + (a[2] - a[0]))){
return 0;
}
memset(mark, false, sizeof mark);
mark[1] = mark[2] = true;
if(solve(a[2] - a[1], a[2] + (a[2] - a[1]))){
return 0;
}
cout << -1;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
316 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
1 ms |
344 KB |
Output is correct |
21 |
Correct |
1 ms |
344 KB |
Output is correct |
22 |
Correct |
1 ms |
344 KB |
Output is correct |
23 |
Correct |
1 ms |
344 KB |
Output is correct |
24 |
Correct |
1 ms |
332 KB |
Output is correct |
25 |
Correct |
1 ms |
332 KB |
Output is correct |
26 |
Correct |
1 ms |
332 KB |
Output is correct |
27 |
Correct |
1 ms |
332 KB |
Output is correct |
28 |
Correct |
1 ms |
332 KB |
Output is correct |
29 |
Correct |
1 ms |
332 KB |
Output is correct |
30 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
32 ms |
2112 KB |
Output is correct |
2 |
Correct |
32 ms |
2124 KB |
Output is correct |
3 |
Correct |
35 ms |
2116 KB |
Output is correct |
4 |
Correct |
35 ms |
2116 KB |
Output is correct |
5 |
Correct |
32 ms |
2116 KB |
Output is correct |
6 |
Correct |
32 ms |
2112 KB |
Output is correct |
7 |
Correct |
34 ms |
2120 KB |
Output is correct |
8 |
Correct |
32 ms |
2116 KB |
Output is correct |
9 |
Correct |
30 ms |
1844 KB |
Output is correct |
10 |
Correct |
32 ms |
2076 KB |
Output is correct |
11 |
Correct |
25 ms |
3156 KB |
Output is correct |
12 |
Correct |
1 ms |
324 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
316 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
1 ms |
344 KB |
Output is correct |
21 |
Correct |
1 ms |
344 KB |
Output is correct |
22 |
Correct |
1 ms |
344 KB |
Output is correct |
23 |
Correct |
1 ms |
344 KB |
Output is correct |
24 |
Correct |
1 ms |
332 KB |
Output is correct |
25 |
Correct |
1 ms |
332 KB |
Output is correct |
26 |
Correct |
1 ms |
332 KB |
Output is correct |
27 |
Correct |
1 ms |
332 KB |
Output is correct |
28 |
Correct |
1 ms |
332 KB |
Output is correct |
29 |
Correct |
1 ms |
332 KB |
Output is correct |
30 |
Correct |
1 ms |
332 KB |
Output is correct |
31 |
Correct |
32 ms |
2112 KB |
Output is correct |
32 |
Correct |
32 ms |
2124 KB |
Output is correct |
33 |
Correct |
35 ms |
2116 KB |
Output is correct |
34 |
Correct |
35 ms |
2116 KB |
Output is correct |
35 |
Correct |
32 ms |
2116 KB |
Output is correct |
36 |
Correct |
32 ms |
2112 KB |
Output is correct |
37 |
Correct |
34 ms |
2120 KB |
Output is correct |
38 |
Correct |
32 ms |
2116 KB |
Output is correct |
39 |
Correct |
30 ms |
1844 KB |
Output is correct |
40 |
Correct |
32 ms |
2076 KB |
Output is correct |
41 |
Correct |
25 ms |
3156 KB |
Output is correct |
42 |
Correct |
1 ms |
324 KB |
Output is correct |
43 |
Correct |
45 ms |
3076 KB |
Output is correct |
44 |
Correct |
22 ms |
2104 KB |
Output is correct |
45 |
Correct |
30 ms |
2508 KB |
Output is correct |
46 |
Correct |
32 ms |
3160 KB |
Output is correct |
47 |
Correct |
22 ms |
2080 KB |
Output is correct |
48 |
Correct |
37 ms |
2440 KB |
Output is correct |
49 |
Correct |
36 ms |
3100 KB |
Output is correct |
50 |
Correct |
21 ms |
2096 KB |
Output is correct |
51 |
Correct |
30 ms |
2628 KB |
Output is correct |
52 |
Correct |
32 ms |
3088 KB |
Output is correct |
53 |
Correct |
22 ms |
2072 KB |
Output is correct |
54 |
Correct |
30 ms |
2500 KB |
Output is correct |
55 |
Correct |
34 ms |
3096 KB |
Output is correct |
56 |
Correct |
28 ms |
3124 KB |
Output is correct |
57 |
Correct |
25 ms |
3148 KB |
Output is correct |
58 |
Correct |
1 ms |
332 KB |
Output is correct |