// iee
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <vector>
#include <set>
#include <map>
#define rep(i, a, b) for (auto i = (a); i <= (b); ++i)
#define per(i, a, b) for (auto i = (a); i >= (b); --i)
#define fi first
#define se second
using ll = long long;
using ull = unsigned long long;
using namespace std;
void work(int);
template <class T> void read(T &x) {
x = 0; int f = 1, ch = getchar();
while (!isdigit(ch)) { if (ch == '-') f = -1; ch = getchar(); }
while (isdigit(ch)) x = x * 10 + (ch - '0'), ch = getchar();
x *= f;
}
int main() {
int TT = 1; // cin >> TT;
rep(CAS, 1, TT)
work(CAS);
return 0;
}
const int N = 1e5 + 5;
int n, a[N];
// int jb[N];
// void solve(int A1, int A2) {
// memset(jb, 0, sizeof jb);
// const int d = a[A2] - a[A1];
// jb[A1] = jb[A2] = 1;
// int las = a[A2];
// rep(i, A2 + 1, n) {
// if (a[i] - las == d) {
// las = a[i];
// jb[i] = 1;
// }
// }
// vector<int> B;
// rep(i, 1, n) if (!jb[i]) B.push_back(a[i]);
// for (int i = 2; i < B.size(); ++i)
// if (B[i] - B[i - 1] != B[1] - B[0]) return;
// cout << n - B.size() << '\n';
// rep(i, 1, n) if (jb[i]) cout << a[i] << ' ';
// cout << '\n' << B.size() << '\n';
// for (int x: B) cout << x << ' ';
// exit(0);
// }
void solve(int A1, int A2) {
multiset<int> B, dB;
rep(i, 1, n) if (i != A1 && i != A2) B.emplace(a[i]);
vector<int> A{a[A1], a[A2]};
int las = -1, d = a[A2] - a[A1];
for (int v: B) {
if (las != -1) dB.emplace(v - las);
las = v;
}
int curA = a[A2] + d;
while (A.size() < n) {
if (*dB.begin() == *prev(dB.end())) {
cout << A.size() << '\n';
for (int x: A) cout << x << ' ';
cout << '\n' << B.size() << '\n';
for (int x: B) cout << x << ' ';
exit(0);
}
auto it = B.find(curA);
if (it == B.end()) return;
if (it != B.begin()) dB.erase(dB.find(curA - *prev(it)));
if (next(it) != B.end()) {
if (it != B.begin()) dB.emplace(*next(it) - *prev(it));
dB.erase(dB.find(*next(it) - curA));
}
B.erase(B.find(curA));
A.push_back(curA);
curA += d;
}
}
void work(int CASE) {
cin >> n;
rep(i, 1, n) cin >> a[i];
sort(a + 1, a + n + 1);
if (n == 2) {
cout << 1 << '\n' << a[1] << '\n' << 1 << '\n' << a[2];
return;
}
if ([&]() { rep(i, 2, n) if (a[i] - a[i - 1] != a[2] - a[1]) return 0; return 1; }()) {
cout << n - 1 << '\n';
rep(i, 1, n - 1) cout << a[i] << ' ';
cout << '\n' << 1 << '\n' << a[n];
return;
}
solve(1, 2), solve(2, 3), solve(1, 3);
puts("-1");
}
Compilation message
drvca.cpp: In function 'void solve(int, int)':
drvca.cpp:66:19: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
66 | while (A.size() < n) {
| ~~~~~~~~~^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
304 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
304 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
304 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
304 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
308 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
308 KB |
Output is correct |
20 |
Correct |
1 ms |
304 KB |
Output is correct |
21 |
Correct |
1 ms |
212 KB |
Output is correct |
22 |
Correct |
1 ms |
212 KB |
Output is correct |
23 |
Correct |
1 ms |
212 KB |
Output is correct |
24 |
Correct |
1 ms |
304 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
212 KB |
Output is correct |
27 |
Correct |
1 ms |
304 KB |
Output is correct |
28 |
Correct |
1 ms |
340 KB |
Output is correct |
29 |
Correct |
0 ms |
212 KB |
Output is correct |
30 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
114 ms |
12124 KB |
Output is correct |
2 |
Correct |
97 ms |
11764 KB |
Output is correct |
3 |
Correct |
123 ms |
12044 KB |
Output is correct |
4 |
Correct |
99 ms |
11664 KB |
Output is correct |
5 |
Correct |
111 ms |
12364 KB |
Output is correct |
6 |
Correct |
98 ms |
11940 KB |
Output is correct |
7 |
Correct |
109 ms |
12492 KB |
Output is correct |
8 |
Correct |
96 ms |
12004 KB |
Output is correct |
9 |
Correct |
91 ms |
11324 KB |
Output is correct |
10 |
Correct |
112 ms |
11980 KB |
Output is correct |
11 |
Correct |
45 ms |
2576 KB |
Output is correct |
12 |
Correct |
0 ms |
308 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
304 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
304 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
308 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
308 KB |
Output is correct |
20 |
Correct |
1 ms |
304 KB |
Output is correct |
21 |
Correct |
1 ms |
212 KB |
Output is correct |
22 |
Correct |
1 ms |
212 KB |
Output is correct |
23 |
Correct |
1 ms |
212 KB |
Output is correct |
24 |
Correct |
1 ms |
304 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
212 KB |
Output is correct |
27 |
Correct |
1 ms |
304 KB |
Output is correct |
28 |
Correct |
1 ms |
340 KB |
Output is correct |
29 |
Correct |
0 ms |
212 KB |
Output is correct |
30 |
Correct |
0 ms |
212 KB |
Output is correct |
31 |
Correct |
114 ms |
12124 KB |
Output is correct |
32 |
Correct |
97 ms |
11764 KB |
Output is correct |
33 |
Correct |
123 ms |
12044 KB |
Output is correct |
34 |
Correct |
99 ms |
11664 KB |
Output is correct |
35 |
Correct |
111 ms |
12364 KB |
Output is correct |
36 |
Correct |
98 ms |
11940 KB |
Output is correct |
37 |
Correct |
109 ms |
12492 KB |
Output is correct |
38 |
Correct |
96 ms |
12004 KB |
Output is correct |
39 |
Correct |
91 ms |
11324 KB |
Output is correct |
40 |
Correct |
112 ms |
11980 KB |
Output is correct |
41 |
Correct |
45 ms |
2576 KB |
Output is correct |
42 |
Correct |
0 ms |
308 KB |
Output is correct |
43 |
Correct |
108 ms |
12192 KB |
Output is correct |
44 |
Correct |
197 ms |
11416 KB |
Output is correct |
45 |
Correct |
86 ms |
11388 KB |
Output is correct |
46 |
Correct |
97 ms |
11980 KB |
Output is correct |
47 |
Correct |
191 ms |
11180 KB |
Output is correct |
48 |
Correct |
84 ms |
11432 KB |
Output is correct |
49 |
Correct |
108 ms |
12232 KB |
Output is correct |
50 |
Correct |
167 ms |
11044 KB |
Output is correct |
51 |
Correct |
85 ms |
11432 KB |
Output is correct |
52 |
Correct |
100 ms |
12024 KB |
Output is correct |
53 |
Correct |
191 ms |
11224 KB |
Output is correct |
54 |
Correct |
90 ms |
11332 KB |
Output is correct |
55 |
Correct |
102 ms |
11996 KB |
Output is correct |
56 |
Correct |
95 ms |
11944 KB |
Output is correct |
57 |
Correct |
46 ms |
2636 KB |
Output is correct |
58 |
Correct |
1 ms |
212 KB |
Output is correct |