# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
443645 |
2021-07-11T06:52:16 Z |
Karliver |
Drvca (COCI19_drvca) |
C++14 |
|
105 ms |
8260 KB |
#include <bits/stdc++.h>
#define FIXED_FLOAT(x) std::fixed <<std::setprecision(20) << (x)
#define all(v) (v).begin(), (v).end()
using namespace std;
#define forn(i,n) for (int i = 0; i < (n); ++i)
#define rforn(i, n) for(int i = (n) - 1;i >= 0;--i)
using ll = long long;
int mod = (ll)1e9 + 7;
#define PI acos(-1)
typedef pair<int, int> pairs;
const int INF = 1e9 + 1;
const int N = 2e5 + 100;
const double eps = 1e-7;
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;
template <typename XPAX>
void ckma(XPAX &x, XPAX y) {
x = (x < y ? y : x);
}
template <typename XPAX>
void ckmi(XPAX &x, XPAX y) {
x = (x > y ? y : x);
}
void write(V<int> a, V<int> b) {
if(b.empty()) {
b.push_back(a.back());
a.pop_back();
}
cout << a.size() << '\n';
for(auto c : a) cout << c << ' ';
cout << '\n';
cout << b.size() << '\n';
for(auto c : b) cout << c << ' ';
exit(0);
}
multiset<int> ps;
int bad = 0;
bool issok(multiset<int>::iterator it) {
auto nxt = it;
++nxt;
if(nxt == ps.end() || it == ps.begin())return true;
auto pr = it;
--pr;
return ((*it - *pr) == (*nxt - *it));
}
void add(int x) {
if(ps.size() < 2) {
ps.insert(x);
return;
}
auto it = ps.insert(x);
--it;
bad += !issok(it);
}
void del(int x) {
auto it = ps.lower_bound(x);
bad -= !issok(it);
auto pr = it;
if(pr != ps.begin()) {
pr--;
bad -= !issok(pr);
}
auto nxt = it;
if(nxt != ps.end()) {
nxt++;
if(nxt != ps.end()) {
bad -= !issok(nxt);
}
}
it = ps.erase(it);
if(it != ps.end()) {
bad += !issok(it);
}
if(it != ps.begin()) {
--it;
bad += !issok(it);
}
}
void solve() {
int n;
cin >> n;
V<int> a(n);
forn(i, n) cin >> a[i];
sort(all(a));
if(n == 2) {
cout << 1 << '\n' << a[0] << '\n' << 1 << '\n' << a[1] << '\n';
return;
}
if(n == 3) {
cout << 2 << '\n' << a[0] << ' ' << a[1] << '\n' << 1 << '\n' << a[2] << '\n';
return;
}
if(n == 4) {
cout << 2 << '\n' << a[0] << ' ' << a[1] << '\n' << 2 << '\n' << a[2] << ' ' << a[3] << '\n';
return;
}
for(int p = 0;p < 3;++p) {
for(int q = p + 1;q < 3;++q) {
int dif = a[q] - a[p];
int nt = a[q] + dif;
ps.clear();
bad = 0;
for(int x = 0;x < n;++x) {
if(x == p || x == q)continue;
add(a[x]);
}
V<int> one{a[p], a[q]}, two;
if(bad == 0) {
for(auto c : ps)two.push_back(c);
write(one, two);
}
for(int x = q + 1;x < n;++x) {
if(a[x] == nt) {
one.push_back(nt);
del(nt);
if(bad == 0) {
for(auto t : ps)
two.push_back(t);
write(one, two);
}
nt += dif;
}
}
}
}
cout << -1 << '\n';
}
void test_case() {
int t;
cin >> t;
forn(p, t) {
//cout << "Case #" << p + 1 << ": ";
solve();
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
solve();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
0 ms |
204 KB |
Output is correct |
13 |
Correct |
0 ms |
204 KB |
Output is correct |
14 |
Correct |
0 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
0 ms |
204 KB |
Output is correct |
13 |
Correct |
0 ms |
204 KB |
Output is correct |
14 |
Correct |
0 ms |
204 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 |
204 KB |
Output is correct |
18 |
Correct |
1 ms |
316 KB |
Output is correct |
19 |
Correct |
1 ms |
312 KB |
Output is correct |
20 |
Correct |
1 ms |
332 KB |
Output is correct |
21 |
Correct |
1 ms |
332 KB |
Output is correct |
22 |
Correct |
1 ms |
332 KB |
Output is correct |
23 |
Correct |
1 ms |
204 KB |
Output is correct |
24 |
Correct |
1 ms |
332 KB |
Output is correct |
25 |
Correct |
1 ms |
204 KB |
Output is correct |
26 |
Correct |
1 ms |
204 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 |
0 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
66 ms |
8260 KB |
Output is correct |
2 |
Correct |
61 ms |
7252 KB |
Output is correct |
3 |
Correct |
67 ms |
8208 KB |
Output is correct |
4 |
Correct |
62 ms |
7408 KB |
Output is correct |
5 |
Correct |
66 ms |
8224 KB |
Output is correct |
6 |
Correct |
61 ms |
7364 KB |
Output is correct |
7 |
Correct |
71 ms |
8252 KB |
Output is correct |
8 |
Correct |
63 ms |
7444 KB |
Output is correct |
9 |
Correct |
61 ms |
6852 KB |
Output is correct |
10 |
Correct |
64 ms |
7676 KB |
Output is correct |
11 |
Correct |
52 ms |
8240 KB |
Output is correct |
12 |
Correct |
0 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
0 ms |
204 KB |
Output is correct |
13 |
Correct |
0 ms |
204 KB |
Output is correct |
14 |
Correct |
0 ms |
204 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 |
204 KB |
Output is correct |
18 |
Correct |
1 ms |
316 KB |
Output is correct |
19 |
Correct |
1 ms |
312 KB |
Output is correct |
20 |
Correct |
1 ms |
332 KB |
Output is correct |
21 |
Correct |
1 ms |
332 KB |
Output is correct |
22 |
Correct |
1 ms |
332 KB |
Output is correct |
23 |
Correct |
1 ms |
204 KB |
Output is correct |
24 |
Correct |
1 ms |
332 KB |
Output is correct |
25 |
Correct |
1 ms |
204 KB |
Output is correct |
26 |
Correct |
1 ms |
204 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 |
0 ms |
204 KB |
Output is correct |
31 |
Correct |
66 ms |
8260 KB |
Output is correct |
32 |
Correct |
61 ms |
7252 KB |
Output is correct |
33 |
Correct |
67 ms |
8208 KB |
Output is correct |
34 |
Correct |
62 ms |
7408 KB |
Output is correct |
35 |
Correct |
66 ms |
8224 KB |
Output is correct |
36 |
Correct |
61 ms |
7364 KB |
Output is correct |
37 |
Correct |
71 ms |
8252 KB |
Output is correct |
38 |
Correct |
63 ms |
7444 KB |
Output is correct |
39 |
Correct |
61 ms |
6852 KB |
Output is correct |
40 |
Correct |
64 ms |
7676 KB |
Output is correct |
41 |
Correct |
52 ms |
8240 KB |
Output is correct |
42 |
Correct |
0 ms |
204 KB |
Output is correct |
43 |
Correct |
67 ms |
7608 KB |
Output is correct |
44 |
Correct |
105 ms |
6756 KB |
Output is correct |
45 |
Correct |
58 ms |
6964 KB |
Output is correct |
46 |
Correct |
61 ms |
7376 KB |
Output is correct |
47 |
Correct |
100 ms |
6540 KB |
Output is correct |
48 |
Correct |
57 ms |
6960 KB |
Output is correct |
49 |
Correct |
65 ms |
7352 KB |
Output is correct |
50 |
Correct |
90 ms |
6468 KB |
Output is correct |
51 |
Correct |
61 ms |
7108 KB |
Output is correct |
52 |
Correct |
63 ms |
7320 KB |
Output is correct |
53 |
Correct |
101 ms |
6580 KB |
Output is correct |
54 |
Correct |
58 ms |
6980 KB |
Output is correct |
55 |
Correct |
65 ms |
7272 KB |
Output is correct |
56 |
Correct |
58 ms |
7280 KB |
Output is correct |
57 |
Correct |
50 ms |
8256 KB |
Output is correct |
58 |
Correct |
0 ms |
204 KB |
Output is correct |