제출 #444734

#제출 시각아이디문제언어결과실행 시간메모리
444734penguinhackerDrvca (COCI19_drvca)C++14
50 / 110
39 ms2972 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...