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=2e5;
int n, a[mxN], prv[mxN], nxt[mxN], cnt;
vector<int> cur={0};
bool rem[mxN]={1}, bad[mxN];
void calc(int i) {
if (i==-1)
return;
cnt-=bad[i];
if (rem[i])
bad[i]=0;
else {
if (prv[i]==-1||nxt[i]==-1)
bad[i]=0;
else {
assert(!rem[prv[i]]&&!rem[nxt[i]]);
bad[i]=a[i]-a[prv[i]]!=a[nxt[i]]-a[i];
}
}
cnt+=bad[i];
}
void ck() {
if (cnt)
return;
assert(cnt==0&&cur.size()&&n-cur.size()>0);
vector<bool> other(n, 1);
cout << cur.size() << "\n";
for (int i : cur) {
other[i]=0;
cout << a[i] << " ";
}
cout << "\n" << n-cur.size() << "\n";
for (int i=0; i<n; ++i)
if (other[i])
cout << a[i] << " ";
exit(0);
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n;
for (int i=0; i<n; ++i)
cin >> a[i];
sort(a, a+n);
for (int i=1; i<n; ++i) {
prv[i]=i-1;
nxt[i]=i+1;
}
prv[1]=-1, nxt[n-1]=-1;
for (int i=1; i<n; ++i)
calc(i);
ck();
for (int i=1; i<n; ++i) {
int d=a[i]-a[0];
for (int j=i; j<n;) {
assert(!rem[j]);
cur.push_back(j);
nxt[prv[j]]=nxt[j], prv[nxt[j]]=prv[j], rem[j]=1;
calc(j), calc(prv[j]), calc(nxt[j]);
ck();
int p=lower_bound(a, a+n, a[j]+d)-a;
p=max(j+1, p);
if (p==n||a[p]!=a[j]+d)
break;
j=p;
}
while(cur.size()>1) {
int j=cur.back();
cur.pop_back();
nxt[prv[j]]=j, prv[nxt[j]]=j, rem[j]=0;
calc(j), calc(prv[j]), calc(nxt[j]);
}
}
cout << -1;
return 0;
}
# | 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... |