# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
442868 | Abrar_Al_Samit | Drvca (COCI19_drvca) | C++17 | 3 ms | 588 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define debug(x) cerr << '[' << (#x) << "] = " << x << '\n';
template<class T> using ordered_set = tree<T, null_type , less<T> , rb_tree_tag , tree_order_statistics_node_update> ;
void PlayGround() {
int N; cin >> N;
vector<int>a(N);
for(int i=0; i<N; ++i) cin >> a[i];
sort(a.begin(), a.end());
vector<int>v0, v1;
v0.push_back(a[0]);
int p = 1;
while(max(v0.size(), v1.size())<2) {
int dif = a[p] - v0[0];
int last = a[p];
vector<int>v3 = v1;
for(int i=p+1; i<N; ++i) {
if(a[i]-last == dif) last = a[i];
else v3.push_back(a[i]);
}
bool evenGap = true;
for(int i=2; i<v3.size(); ++i) {
evenGap &= v3[i]-v3[i-1]==v3[i-1]-v3[i-2];
}
if(evenGap) {
v0.push_back(a[p++]);
break;
} else {
v1.push_back(a[p++]);
}
}
if(v0.size()==1) swap(v0, v1);
int last = v0[1], dif = v0[1] - v0[0];
for(int i=p; i<N; ++i) {
if(dif + last == a[i]) v0.push_back(a[i]), last = a[i];
else v1.push_back(a[i]);
}
bool evenGap = true;
for(int i=2; i<v1.size(); ++i) {
evenGap &= v1[i]-v1[i-1]==v1[i-1]-v1[i-2];
}
if(v1.empty()) v1.push_back(v0.back()), v0.pop_back();
if(evenGap) {
assert((int)(v0.size()+v1.size())==N);
cout << v0.size() << '\n';
for(auto it : v0) cout << it << ' ';
cout << '\n';
cout << v1.size() << '\n';
for(auto it : v1) cout << it << ' ';
cout << '\n';
} else cout << -1 << '\n';
#ifndef ONLINE_JUDGE
cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
#endif
PlayGround();
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |