This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#pragma GCC optimize("O3", "unroll-loops") // "Ofast"
#pragma GCC target("avx2", "bmi", "bmi2", "lzcnt", "popcnt")
#include <bits/stdc++.h>
//#define int long long
#define vt vector
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
#define ff first
#define ss second
#define dbg(x) cerr << #x << " = " << x << '\n'
#define bit(x, i) ((x) >> (i) & 1)
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vvt = vt< vt<int> >;
const int N = 1e6 + 5, mod = 1e9 + 7, B = 500;
const ll inf = 1e18 + 7, LIM = (1ll << 60);
const double eps = 1e-6;
int n, a[N];
void go (int x, int y) {
multiset<int> diff, R;
vt<int> L;
int d = a[y] - a[x], lst = -1;
for (int i = 1; i <= n; i++) {
if (i == x || i == y) continue;
R.insert(a[i]);
}
L.pb(a[x]), L.pb(a[y]);
for (int i: R) {
if (lst != -1) diff.insert(i - lst);
lst = i;
}
int cur = a[y] + d;
do {
if (*diff.begin() == *diff.rbegin()) {
cout << sz(L) << '\n';
for (int i: L) cout << i << ' ';
cout << '\n';
cout << sz(R) << '\n';
for (int i: R) cout << i << ' ';
cout << '\n';
exit(0);
}
auto it = R.find(cur);
if (it == R.end()) return;
auto l = it, r = it;
if (it != R.begin()) {
l--;
diff.erase(diff.find(*it - *l));
}
r++;
if (r != R.end()) {
diff.erase(diff.find(*r - *it));
if (it != R.begin()) diff.insert(*r - *l);
}
R.erase(it);
L.pb(cur);
cur += d;
} while (sz(L) < n);
}
void solve () {
cin >> n;
for (int i = 1; i <= n; i++) cin >> a[i];
sort(a + 1, a + n + 1);
if (n == 2) {
cout << "1\n" << a[1] << "\n1\n" << a[2] << '\n';
return;
}
if (n == 3) {
cout << "2\n" << a[1] << ' ' << a[2] << "\n1\n" << a[3] << '\n';
return;
}
for (int i = 1; i <= 3; i++) {
for (int j = i + 1; j <= 3; j++) go(i, j);
}
cout << -1;
cout << '\n';
}
bool testcases = 0;
signed main() {
#ifdef ONLINE_JUDGE
freopen(".in", "r", stdin);
freopen(".out", "w", stdout);
#endif
cin.tie(0) -> sync_with_stdio(0);
int test = 1;
if (testcases) cin >> test;
for (int cs = 1; cs <= test; cs++) {
solve();
}
}
# | 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... |