# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
496032 |
2021-12-20T12:51:01 Z |
AlperenT |
Drvca (COCI19_drvca) |
C++17 |
|
46 ms |
4092 KB |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int n, arr[N], dif, cur, nxt;
bool vis[N];
vector<int> a, b, ansa, ansb;
bool check(vector<int> v){
for(int i = 2; i < v.size(); i++) if(arr[v[i]] - arr[v[i - 1]] != arr[v[1]] - arr[v[0]]) return false;
return true;
}
int main(){
ios_base::sync_with_stdio(false);cin.tie(NULL);
cin >> n;
for(int i = 1; i <= n; i++) cin >> arr[i];
sort(arr + 1, arr + n + 1);
if(arr[1] != arr[2]){
a.clear(), b.clear(); memset(vis, 0, sizeof(vis));
a.push_back(1); a.push_back(2);
vis[1] = vis[2] = true;
dif = arr[2] - arr[1];
cur = 2;
while(true){
nxt = lower_bound(arr + 1, arr + n + 1, arr[cur] + dif) - arr;
if(nxt > n || arr[nxt] != arr[cur] + dif) break;
vis[nxt] = true;
a.push_back(nxt);
cur = nxt;
}
cur = -1;
for(int i = 1; i <= n; i++){
if(!vis[i]){
if(b.size() < 2){
b.push_back(i);
cur = i;
}
}
}
if(b.size() == 2){
dif = arr[b[1]] - arr[b[0]];
while(true){
nxt = lower_bound(arr + 1, arr + n + 1, arr[cur] + dif) - arr;
if(nxt > n || arr[nxt] != arr[cur] + dif) break;
else if(vis[nxt]){
if(nxt + 1 <= n && arr[nxt + 1] == arr[nxt]) nxt++;
else{
while(a.back() >= nxt){
vis[a.back()] = false;
a.pop_back();
}
}
}
vis[nxt] = true;
b.push_back(nxt);
cur = nxt;
}
}
if(check(a) && check(b) && a.size() + b.size() == n) ansa = a, ansb = b;
}
else{
a.clear(), b.clear();
for(int i = 1; i <= n; i++){
if(arr[i] == arr[1]) a.push_back(i);
else b.push_back(i);
}
if(check(a) && check(b) && a.size() + b.size() == n) ansa = a, ansb = b;
}
if(n >= 3 && arr[1] != arr[3]){
a.clear(), b.clear(); memset(vis, 0, sizeof(vis));
a.push_back(1); a.push_back(3);
vis[1] = vis[3] = true;
dif = arr[3] - arr[1];
cur = 3;
while(true){
nxt = lower_bound(arr + 1, arr + n + 1, arr[cur] + dif) - arr;
if(nxt > n || arr[nxt] != arr[cur] + dif) break;
vis[nxt] = true;
a.push_back(nxt);
cur = nxt;
}
cur = -1;
for(int i = 1; i <= n; i++){
if(!vis[i]){
if(b.size() < 2){
b.push_back(i);
cur = i;
}
}
}
if(b.size() == 2){
dif = arr[b[1]] - arr[b[0]];
while(true){
nxt = lower_bound(arr + 1, arr + n + 1, arr[cur] + dif) - arr;
if(nxt > n || arr[nxt] != arr[cur] + dif) break;
else if(vis[nxt]){
if(nxt + 1 <= n && arr[nxt + 1] == arr[nxt]) nxt++;
else{
while(a.back() >= nxt){
vis[a.back()] = false;
a.pop_back();
}
}
}
vis[nxt] = true;
b.push_back(nxt);
cur = nxt;
}
}
if(check(a) && check(b) && a.size() + b.size() == n) ansa = a, ansb = b;
}
if(n >= 3 && arr[2] != arr[3]){
a.clear(), b.clear(); memset(vis, 0, sizeof(vis));
a.push_back(2); a.push_back(3);
vis[2] = vis[3] = true;
dif = arr[3] - arr[2];
cur = 3;
while(true){
nxt = lower_bound(arr + 1, arr + n + 1, arr[cur] + dif) - arr;
if(nxt > n || arr[nxt] != arr[cur] + dif) break;
vis[nxt] = true;
a.push_back(nxt);
cur = nxt;
}
cur = -1;
for(int i = 1; i <= n; i++){
if(!vis[i]){
if(b.size() < 2){
b.push_back(i);
cur = i;
}
}
}
if(b.size() == 2){
dif = arr[b[1]] - arr[b[0]];
while(true){
nxt = lower_bound(arr + 1, arr + n + 1, arr[cur] + dif) - arr;
if(nxt > n || arr[nxt] != arr[cur] + dif) break;
else if(vis[nxt]){
if(nxt + 1 <= n && arr[nxt + 1] == arr[nxt]) nxt++;
else{
while(a.back() >= nxt){
vis[a.back()] = false;
a.pop_back();
}
}
}
vis[nxt] = true;
b.push_back(nxt);
cur = nxt;
}
}
if(check(a) && check(b) && a.size() + b.size() == n) ansa = a, ansb = b;
}
else if(n >= 3){
a.clear(), b.clear();
for(int i = 1; i <= n; i++){
if(arr[i] == arr[2]) a.push_back(i);
else b.push_back(i);
}
if(check(a) && check(b) && a.size() + b.size() == n) ansa = a, ansb = b;
}
if(ansb.size() > ansa.size()) swap(ansb, ansa);
if(ansa.size() == 0) cout << -1;
else{
if(ansb.size() == 0) ansb.push_back(ansa.back()), ansa.pop_back();
cout << ansa.size() << "\n";
for(auto i : ansa) cout << arr[i] << " ";
cout << "\n";
cout << ansb.size() << "\n";
for(auto i : ansb) cout << arr[i] << " ";
cout << "\n";
}
}
Compilation message
drvca.cpp: In function 'bool check(std::vector<int>)':
drvca.cpp:14:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
14 | for(int i = 2; i < v.size(); i++) if(arr[v[i]] - arr[v[i - 1]] != arr[v[1]] - arr[v[0]]) return false;
| ~~^~~~~~~~~~
drvca.cpp: In function 'int main()':
drvca.cpp:79:56: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
79 | if(check(a) && check(b) && a.size() + b.size() == n) ansa = a, ansb = b;
| ~~~~~~~~~~~~~~~~~~~~^~~~
drvca.cpp:89:56: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
89 | if(check(a) && check(b) && a.size() + b.size() == n) ansa = a, ansb = b;
| ~~~~~~~~~~~~~~~~~~~~^~~~
drvca.cpp:143:56: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
143 | if(check(a) && check(b) && a.size() + b.size() == n) ansa = a, ansb = b;
| ~~~~~~~~~~~~~~~~~~~~^~~~
drvca.cpp:197:56: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
197 | if(check(a) && check(b) && a.size() + b.size() == n) ansa = a, ansb = b;
| ~~~~~~~~~~~~~~~~~~~~^~~~
drvca.cpp:207:56: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
207 | if(check(a) && check(b) && a.size() + b.size() == n) ansa = a, ansb = b;
| ~~~~~~~~~~~~~~~~~~~~^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
0 ms |
332 KB |
Output is correct |
4 |
Correct |
0 ms |
332 KB |
Output is correct |
5 |
Correct |
0 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
412 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 |
0 ms |
332 KB |
Output is correct |
11 |
Correct |
0 ms |
332 KB |
Output is correct |
12 |
Correct |
0 ms |
320 KB |
Output is correct |
13 |
Correct |
1 ms |
208 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
0 ms |
332 KB |
Output is correct |
4 |
Correct |
0 ms |
332 KB |
Output is correct |
5 |
Correct |
0 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
412 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 |
0 ms |
332 KB |
Output is correct |
11 |
Correct |
0 ms |
332 KB |
Output is correct |
12 |
Correct |
0 ms |
320 KB |
Output is correct |
13 |
Correct |
1 ms |
208 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
15 |
Correct |
1 ms |
336 KB |
Output is correct |
16 |
Correct |
1 ms |
336 KB |
Output is correct |
17 |
Correct |
1 ms |
336 KB |
Output is correct |
18 |
Correct |
1 ms |
336 KB |
Output is correct |
19 |
Correct |
1 ms |
424 KB |
Output is correct |
20 |
Correct |
1 ms |
336 KB |
Output is correct |
21 |
Correct |
0 ms |
336 KB |
Output is correct |
22 |
Correct |
1 ms |
336 KB |
Output is correct |
23 |
Correct |
1 ms |
336 KB |
Output is correct |
24 |
Correct |
1 ms |
324 KB |
Output is correct |
25 |
Correct |
1 ms |
336 KB |
Output is correct |
26 |
Correct |
1 ms |
336 KB |
Output is correct |
27 |
Correct |
1 ms |
336 KB |
Output is correct |
28 |
Correct |
0 ms |
336 KB |
Output is correct |
29 |
Correct |
1 ms |
324 KB |
Output is correct |
30 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
40 ms |
2740 KB |
Output is correct |
2 |
Correct |
36 ms |
2748 KB |
Output is correct |
3 |
Correct |
37 ms |
2748 KB |
Output is correct |
4 |
Correct |
37 ms |
2784 KB |
Output is correct |
5 |
Correct |
37 ms |
2752 KB |
Output is correct |
6 |
Correct |
38 ms |
2796 KB |
Output is correct |
7 |
Correct |
40 ms |
2672 KB |
Output is correct |
8 |
Correct |
36 ms |
2740 KB |
Output is correct |
9 |
Correct |
37 ms |
2488 KB |
Output is correct |
10 |
Correct |
40 ms |
2752 KB |
Output is correct |
11 |
Correct |
21 ms |
3776 KB |
Output is correct |
12 |
Correct |
0 ms |
312 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
0 ms |
332 KB |
Output is correct |
4 |
Correct |
0 ms |
332 KB |
Output is correct |
5 |
Correct |
0 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
412 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 |
0 ms |
332 KB |
Output is correct |
11 |
Correct |
0 ms |
332 KB |
Output is correct |
12 |
Correct |
0 ms |
320 KB |
Output is correct |
13 |
Correct |
1 ms |
208 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
15 |
Correct |
1 ms |
336 KB |
Output is correct |
16 |
Correct |
1 ms |
336 KB |
Output is correct |
17 |
Correct |
1 ms |
336 KB |
Output is correct |
18 |
Correct |
1 ms |
336 KB |
Output is correct |
19 |
Correct |
1 ms |
424 KB |
Output is correct |
20 |
Correct |
1 ms |
336 KB |
Output is correct |
21 |
Correct |
0 ms |
336 KB |
Output is correct |
22 |
Correct |
1 ms |
336 KB |
Output is correct |
23 |
Correct |
1 ms |
336 KB |
Output is correct |
24 |
Correct |
1 ms |
324 KB |
Output is correct |
25 |
Correct |
1 ms |
336 KB |
Output is correct |
26 |
Correct |
1 ms |
336 KB |
Output is correct |
27 |
Correct |
1 ms |
336 KB |
Output is correct |
28 |
Correct |
0 ms |
336 KB |
Output is correct |
29 |
Correct |
1 ms |
324 KB |
Output is correct |
30 |
Correct |
1 ms |
336 KB |
Output is correct |
31 |
Correct |
40 ms |
2740 KB |
Output is correct |
32 |
Correct |
36 ms |
2748 KB |
Output is correct |
33 |
Correct |
37 ms |
2748 KB |
Output is correct |
34 |
Correct |
37 ms |
2784 KB |
Output is correct |
35 |
Correct |
37 ms |
2752 KB |
Output is correct |
36 |
Correct |
38 ms |
2796 KB |
Output is correct |
37 |
Correct |
40 ms |
2672 KB |
Output is correct |
38 |
Correct |
36 ms |
2740 KB |
Output is correct |
39 |
Correct |
37 ms |
2488 KB |
Output is correct |
40 |
Correct |
40 ms |
2752 KB |
Output is correct |
41 |
Correct |
21 ms |
3776 KB |
Output is correct |
42 |
Correct |
0 ms |
312 KB |
Output is correct |
43 |
Correct |
40 ms |
3792 KB |
Output is correct |
44 |
Correct |
30 ms |
2544 KB |
Output is correct |
45 |
Correct |
34 ms |
3080 KB |
Output is correct |
46 |
Correct |
39 ms |
3732 KB |
Output is correct |
47 |
Correct |
27 ms |
2360 KB |
Output is correct |
48 |
Correct |
35 ms |
3196 KB |
Output is correct |
49 |
Correct |
40 ms |
3772 KB |
Output is correct |
50 |
Correct |
27 ms |
2276 KB |
Output is correct |
51 |
Correct |
41 ms |
3236 KB |
Output is correct |
52 |
Correct |
46 ms |
3896 KB |
Output is correct |
53 |
Correct |
28 ms |
2368 KB |
Output is correct |
54 |
Correct |
35 ms |
3072 KB |
Output is correct |
55 |
Correct |
40 ms |
4092 KB |
Output is correct |
56 |
Correct |
21 ms |
3820 KB |
Output is correct |
57 |
Correct |
21 ms |
3756 KB |
Output is correct |
58 |
Correct |
1 ms |
336 KB |
Output is correct |