# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
439988 |
2021-07-01T10:49:10 Z |
hivakarami |
Drvca (COCI19_drvca) |
C++14 |
|
63 ms |
3544 KB |
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define f first
#define s second
#define pb push_back
#define pii pair<int, int>
const int N = 1e5 + 5;
const ll inf = 1e9 * 600;
const ll mod = 1e9 + 7;
const int lg = 30;
vector<int> v1, v2;
bool ok[N], mark[N];
int a[N], n;
inline bool solve(int x, int y)
{
//cout << x << ' ' << y << endl;
for(int i = 0; i < n; i++)
mark[i] = false;
v1.clear();
v2.clear();
mark[x] = mark[y] = true;
int r = a[y] - a[x], last = a[y];
for(int i = y+1; i < n; i++)
{
if(a[i] - last == r)
{
mark[i] = true;
last = a[i];
}
}
//for(int i = 0; i < n; i++)
//cout << mark[i];
//cout << endl;
r = 0;
for(int i = 0; i < n; i++)
{
if(mark[i])
{
v1.pb(a[i]);
if(!ok[i+1])
continue;
int k = v2.size();
if(i == n-1)
{
for(int j = i+1; j < n; j++)
v2.pb(a[j]);
return true;
}
if(k == 0)
{
for(int j = i+1; j < n; j++)
v2.pb(a[j]);
return true;
}
if(k == 1 && i == n-2)
{
for(int j = i+1; j < n; j++)
v2.pb(a[j]);
return true;
}
if(k == 1 && a[n-1] - a[n-2] == a[i+1] - v2[k-1])
{
for(int j = i+1; j < n; j++)
v2.pb(a[j]);
return true;
}
if(i == n-2 && a[i+1] - v2[k-1] == r)
{
for(int j = i+1; j < n; j++)
v2.pb(a[j]);
return true;
}
if(r == a[n-1] - a[n-2] && r == a[i+1] - v2[k-1])
{
for(int j = i+1; j < n; j++)
v2.pb(a[j]);
return true;
}
}
else
{
v2.pb(a[i]);
int k = v2.size();
if(k == 2)
r = v2[1] - v2[0];
if(k >= 2 && v2[k-1] - v2[k-2] != r)
return false;
}
}
return false;
}
inline void print()
{
cout << v1.size() << endl;
for(auto it : v1)
cout << it << ' ';
cout << endl;
cout << v2.size() << endl;
for(auto it : v2)
cout << it << ' ';
cout << endl;
}
int main()
{
ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
cin >> n;
for(int i = 0; i < n; i++)
cin >> a[i];
sort(a, a+n);
ok[n] = ok[n-1] = ok[n-2] = true;
for(int i = n-3; i >= 0; i--)
{
if(a[i+2] - a[i+1] == a[i+1] - a[i])
ok[i] = true;
else
break;
}
/*
for(int i = 0; i < n; i++)
cout << ok[i];
cout << endl;
//*/
if(solve(0, 1))
{
print();
}
else if(solve(0, 2))
{
print();
}
else if(solve(1, 2))
{
print();
}
else
{
cout << -1 << endl;
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
204 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 |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
204 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 |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
0 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 |
332 KB |
Output is correct |
19 |
Correct |
1 ms |
204 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 |
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 |
0 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
33 ms |
2644 KB |
Output is correct |
2 |
Correct |
63 ms |
3284 KB |
Output is correct |
3 |
Correct |
36 ms |
3348 KB |
Output is correct |
4 |
Correct |
39 ms |
3272 KB |
Output is correct |
5 |
Correct |
36 ms |
3392 KB |
Output is correct |
6 |
Correct |
35 ms |
3356 KB |
Output is correct |
7 |
Correct |
39 ms |
3368 KB |
Output is correct |
8 |
Correct |
42 ms |
3268 KB |
Output is correct |
9 |
Correct |
34 ms |
2668 KB |
Output is correct |
10 |
Correct |
34 ms |
3312 KB |
Output is correct |
11 |
Correct |
30 ms |
3544 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
204 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 |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
0 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 |
332 KB |
Output is correct |
19 |
Correct |
1 ms |
204 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 |
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 |
0 ms |
332 KB |
Output is correct |
31 |
Correct |
33 ms |
2644 KB |
Output is correct |
32 |
Correct |
63 ms |
3284 KB |
Output is correct |
33 |
Correct |
36 ms |
3348 KB |
Output is correct |
34 |
Correct |
39 ms |
3272 KB |
Output is correct |
35 |
Correct |
36 ms |
3392 KB |
Output is correct |
36 |
Correct |
35 ms |
3356 KB |
Output is correct |
37 |
Correct |
39 ms |
3368 KB |
Output is correct |
38 |
Correct |
42 ms |
3268 KB |
Output is correct |
39 |
Correct |
34 ms |
2668 KB |
Output is correct |
40 |
Correct |
34 ms |
3312 KB |
Output is correct |
41 |
Correct |
30 ms |
3544 KB |
Output is correct |
42 |
Correct |
1 ms |
332 KB |
Output is correct |
43 |
Correct |
34 ms |
3324 KB |
Output is correct |
44 |
Correct |
25 ms |
2172 KB |
Output is correct |
45 |
Correct |
37 ms |
2748 KB |
Output is correct |
46 |
Correct |
39 ms |
3344 KB |
Output is correct |
47 |
Correct |
22 ms |
2120 KB |
Output is correct |
48 |
Correct |
33 ms |
2760 KB |
Output is correct |
49 |
Correct |
36 ms |
3324 KB |
Output is correct |
50 |
Correct |
23 ms |
1988 KB |
Output is correct |
51 |
Correct |
31 ms |
2824 KB |
Output is correct |
52 |
Correct |
34 ms |
3312 KB |
Output is correct |
53 |
Correct |
23 ms |
2196 KB |
Output is correct |
54 |
Correct |
30 ms |
2656 KB |
Output is correct |
55 |
Correct |
33 ms |
3260 KB |
Output is correct |
56 |
Correct |
26 ms |
3320 KB |
Output is correct |
57 |
Correct |
26 ms |
3388 KB |
Output is correct |
58 |
Correct |
1 ms |
332 KB |
Output is correct |