이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ar array
const int mxN=1e5;
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<0||i>=n)
return;
cnt-=bad[i];
if (rem[i])
bad[i]=0;
else {
if (prv[i]<0||rem[prv[i]]||nxt[i]>=n||rem[nxt[i]])
bad[i]=0;
else
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];
prv[i]=i-1;
nxt[i]=i+1;
}
sort(a, a+n);
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... |