#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5+10;
int n;
int niz[maxn];
vector<int> a;
multiset<int> b;
map<int, int> m;
void print() {
printf("%d\n", a.size());
for (int i = 0; i < a.size(); i++)
printf("%d ", a[i]);
printf("\n%d\n", b.size());
for (auto iter = b.begin(); iter != b.end(); iter++)
printf("%d ", *iter);
printf("\n");
}
void print_deb() {
printf("a: ");
for (int i = 0; i < a.size(); i++)
printf("%d ", a[i]);
printf("\nb: ");
for (auto iter = b.begin(); iter != b.end(); iter++)
printf("%d ", *iter);
printf("\nm: ");
for (auto iter = m.begin(); iter != m.end(); iter++)
printf("(%d, %d) ", iter->first, iter->second);
printf("\n\n");
}
void check(int x, int y) {
a.clear();
b.clear();
m.clear();
int dif = niz[y] - niz[x];
a.push_back(niz[x]);
a.push_back(niz[y]);
int last = -1;
for (int i = 0; i < n; i++) {
if (i == x || i == y) continue;
if (niz[i] == a.back() + dif) a.push_back(niz[i]);
else {
b.insert(niz[i]);
if (last != -1) m[niz[i] - last]++;
last = niz[i];
}
}
if (m.size() == 1) {
print();
exit(0);
}
//print_deb();
while (!a.empty()) {
int tren = a.back();
int pref, nex;
auto iter = b.lower_bound(tren);
if (iter == b.begin()) pref = -1;
else pref = *(--iter), iter++;
if (iter == b.end()) nex = -1;
else nex = *iter;
if (pref != -1) m[tren - pref]++;
if (nex != -1) m[nex - tren]++;
if (pref != -1 && nex != -1) {
//printf("retard: %d %d -> %d\n", nex, pref, nex - pref);
m[nex - pref]--;
if (m[nex - pref] == 0) m.erase(nex - pref);
}
a.pop_back();
b.insert(tren);
//printf("prev, nex: %d, %d\n", pref, nex);
//print_deb();
if (m.size() == 1) {
print();
exit(0);
}
}
}
int main() {
scanf("%d", &n);
for (int i = 0; i < n; i++)
scanf("%d", niz+i);
sort(niz, niz+n);
if (n < 5) {
printf("%d\n", n / 2);
for (int i = 0; i < n / 2; i++)
printf("%d ", niz[i]);
printf("\n%d\n", n - n / 2);
for (int i = 0; i < n - n / 2; i++)
printf("%d ", niz[n / 2 + i]);
printf("\n");
return 0;
}
check(0, 1);
check(0, 2);
check(1, 2);
printf("-1\n");
return 0;
}
Compilation message
drvca.cpp: In function 'void print()':
drvca.cpp:13:28: warning: format '%d' expects argument of type 'int', but argument 2 has type 'std::vector<int>::size_type {aka long unsigned int}' [-Wformat=]
printf("%d\n", a.size());
~~~~~~~~^
drvca.cpp:14:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0; i < a.size(); i++)
~~^~~~~~~~~~
drvca.cpp:17:30: warning: format '%d' expects argument of type 'int', but argument 2 has type 'std::multiset<int>::size_type {aka long unsigned int}' [-Wformat=]
printf("\n%d\n", b.size());
~~~~~~~~^
drvca.cpp: In function 'void print_deb()':
drvca.cpp:25:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0; i < a.size(); i++)
~~^~~~~~~~~~
drvca.cpp: In function 'int main()':
drvca.cpp:95:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &n);
~~~~~^~~~~~~~~~
drvca.cpp:97:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", niz+i);
~~~~~^~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
256 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
256 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
256 KB |
Output is correct |
7 |
Correct |
5 ms |
256 KB |
Output is correct |
8 |
Correct |
5 ms |
384 KB |
Output is correct |
9 |
Correct |
5 ms |
256 KB |
Output is correct |
10 |
Correct |
5 ms |
256 KB |
Output is correct |
11 |
Correct |
5 ms |
384 KB |
Output is correct |
12 |
Correct |
5 ms |
256 KB |
Output is correct |
13 |
Correct |
5 ms |
256 KB |
Output is correct |
14 |
Correct |
5 ms |
256 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
256 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
256 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
256 KB |
Output is correct |
7 |
Correct |
5 ms |
256 KB |
Output is correct |
8 |
Correct |
5 ms |
384 KB |
Output is correct |
9 |
Correct |
5 ms |
256 KB |
Output is correct |
10 |
Correct |
5 ms |
256 KB |
Output is correct |
11 |
Correct |
5 ms |
384 KB |
Output is correct |
12 |
Correct |
5 ms |
256 KB |
Output is correct |
13 |
Correct |
5 ms |
256 KB |
Output is correct |
14 |
Correct |
5 ms |
256 KB |
Output is correct |
15 |
Correct |
5 ms |
384 KB |
Output is correct |
16 |
Correct |
5 ms |
384 KB |
Output is correct |
17 |
Correct |
5 ms |
384 KB |
Output is correct |
18 |
Correct |
5 ms |
384 KB |
Output is correct |
19 |
Correct |
6 ms |
384 KB |
Output is correct |
20 |
Correct |
5 ms |
384 KB |
Output is correct |
21 |
Correct |
5 ms |
384 KB |
Output is correct |
22 |
Correct |
5 ms |
384 KB |
Output is correct |
23 |
Correct |
5 ms |
256 KB |
Output is correct |
24 |
Correct |
5 ms |
384 KB |
Output is correct |
25 |
Correct |
5 ms |
384 KB |
Output is correct |
26 |
Correct |
5 ms |
384 KB |
Output is correct |
27 |
Correct |
5 ms |
384 KB |
Output is correct |
28 |
Correct |
5 ms |
384 KB |
Output is correct |
29 |
Correct |
5 ms |
384 KB |
Output is correct |
30 |
Correct |
5 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
52 ms |
5236 KB |
Output is correct |
2 |
Correct |
52 ms |
5236 KB |
Output is correct |
3 |
Correct |
53 ms |
5236 KB |
Output is correct |
4 |
Correct |
52 ms |
5364 KB |
Output is correct |
5 |
Correct |
51 ms |
5236 KB |
Output is correct |
6 |
Correct |
54 ms |
5236 KB |
Output is correct |
7 |
Correct |
52 ms |
5236 KB |
Output is correct |
8 |
Correct |
52 ms |
5236 KB |
Output is correct |
9 |
Correct |
49 ms |
4596 KB |
Output is correct |
10 |
Correct |
51 ms |
5236 KB |
Output is correct |
11 |
Correct |
32 ms |
3184 KB |
Output is correct |
12 |
Correct |
5 ms |
256 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
256 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
256 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
256 KB |
Output is correct |
7 |
Correct |
5 ms |
256 KB |
Output is correct |
8 |
Correct |
5 ms |
384 KB |
Output is correct |
9 |
Correct |
5 ms |
256 KB |
Output is correct |
10 |
Correct |
5 ms |
256 KB |
Output is correct |
11 |
Correct |
5 ms |
384 KB |
Output is correct |
12 |
Correct |
5 ms |
256 KB |
Output is correct |
13 |
Correct |
5 ms |
256 KB |
Output is correct |
14 |
Correct |
5 ms |
256 KB |
Output is correct |
15 |
Correct |
5 ms |
384 KB |
Output is correct |
16 |
Correct |
5 ms |
384 KB |
Output is correct |
17 |
Correct |
5 ms |
384 KB |
Output is correct |
18 |
Correct |
5 ms |
384 KB |
Output is correct |
19 |
Correct |
6 ms |
384 KB |
Output is correct |
20 |
Correct |
5 ms |
384 KB |
Output is correct |
21 |
Correct |
5 ms |
384 KB |
Output is correct |
22 |
Correct |
5 ms |
384 KB |
Output is correct |
23 |
Correct |
5 ms |
256 KB |
Output is correct |
24 |
Correct |
5 ms |
384 KB |
Output is correct |
25 |
Correct |
5 ms |
384 KB |
Output is correct |
26 |
Correct |
5 ms |
384 KB |
Output is correct |
27 |
Correct |
5 ms |
384 KB |
Output is correct |
28 |
Correct |
5 ms |
384 KB |
Output is correct |
29 |
Correct |
5 ms |
384 KB |
Output is correct |
30 |
Correct |
5 ms |
384 KB |
Output is correct |
31 |
Correct |
52 ms |
5236 KB |
Output is correct |
32 |
Correct |
52 ms |
5236 KB |
Output is correct |
33 |
Correct |
53 ms |
5236 KB |
Output is correct |
34 |
Correct |
52 ms |
5364 KB |
Output is correct |
35 |
Correct |
51 ms |
5236 KB |
Output is correct |
36 |
Correct |
54 ms |
5236 KB |
Output is correct |
37 |
Correct |
52 ms |
5236 KB |
Output is correct |
38 |
Correct |
52 ms |
5236 KB |
Output is correct |
39 |
Correct |
49 ms |
4596 KB |
Output is correct |
40 |
Correct |
51 ms |
5236 KB |
Output is correct |
41 |
Correct |
32 ms |
3184 KB |
Output is correct |
42 |
Correct |
5 ms |
256 KB |
Output is correct |
43 |
Correct |
49 ms |
4884 KB |
Output is correct |
44 |
Correct |
109 ms |
6900 KB |
Output is correct |
45 |
Correct |
53 ms |
5796 KB |
Output is correct |
46 |
Correct |
50 ms |
4852 KB |
Output is correct |
47 |
Correct |
99 ms |
6644 KB |
Output is correct |
48 |
Correct |
55 ms |
5752 KB |
Output is correct |
49 |
Correct |
51 ms |
4596 KB |
Output is correct |
50 |
Correct |
89 ms |
6648 KB |
Output is correct |
51 |
Correct |
58 ms |
5876 KB |
Output is correct |
52 |
Correct |
42 ms |
3184 KB |
Output is correct |
53 |
Correct |
94 ms |
6644 KB |
Output is correct |
54 |
Correct |
60 ms |
5748 KB |
Output is correct |
55 |
Correct |
46 ms |
4208 KB |
Output is correct |
56 |
Correct |
35 ms |
3824 KB |
Output is correct |
57 |
Correct |
31 ms |
3184 KB |
Output is correct |
58 |
Correct |
5 ms |
256 KB |
Output is correct |