# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
291927 | penguinhacker | Drvca (COCI19_drvca) | C++17 | 1067 ms | 3144 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>
using namespace std;
#define ll long long
#define ar array
const int mxN=1e5;
int n, h[mxN];
vector<int> ans[2];
bool chk(vector<int>& v) {
if (v.size()<3) return 1;
return v[1]-v[0]==v.back()-v[v.size()-2];
}
void solve(int x) {
ans[1].clear();
ans[0]={h[0], h[x]};
for (int i=1; i<x; ++i) {
ans[1].push_back(h[i]);
if (!chk(ans[1])) {
cout << "-1\n";
exit(0);
}
}
int d=h[x]-h[0];
for (int i=x+1; i<n; ++i) {
if (h[i]-ans[0].back()==d) {
ans[0].push_back(h[i]);
}
else {
ans[1].push_back(h[i]);
if (!chk(ans[1])) return;
}
}
if (ans[0].size()==n) {
ans[0].pop_back();
ans[1]={h[n-1]};
}
cout << ans[0].size() << "\n";
for (int i : ans[0]) cout << i << " ";
cout << "\n";
cout << ans[1].size() << "\n";
for (int i : ans[1]) cout << i << " ";
exit(0);
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
ans[0].reserve(mxN);
ans[1].reserve(mxN);
cin >> n;
for (int i=0; i<n; ++i) cin >> h[i];
sort(h, h+n);
for (int i=1; i<n; ++i) solve(i);
cout << -1 << "\n";
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... |