#include<bits/stdc++.h>
using namespace std;
const bool multiTest = false;
#define task "C"
#define fi first
#define se second
#define MASK(i) (1LL << (i))
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define BIT(mask, i) ((mask) >> (i) & 1)
template<typename T1, typename T2> bool minimize(T1 &a, T2 b) {
if (a > b) a = b; else return 0; return 1;
}
template<typename T1, typename T2> bool maximize(T1 &a, T2 b) {
if (a < b) a = b; else return 0; return 1;
}
const int MAX = 100010;
int n, h[MAX];
bool checkValid(vector<bool> &flag) {
int last = -1, df = -1;
for (int i = 1; i <= n; ++i) if (!flag[i]) {
if (last != -1) {
if (df == -1) df = h[i] - last; else
if (h[i] - last != df) return false;
}
last = h[i];
}
return true;
}
void process(void) {
cin >> n; for (int i = 1; i <= n; ++i) cin >> h[i];
sort(h + 1, h + 1 + n);
{ // Case 1: A = {h[1], h[2], ...}, B = {...}
vector<bool> flag(n + 1, false);
int df = h[2] - h[1];
flag[1] = 1;
int pos = 1;
int cnt = 1;
while (pos < n) {
int nextPos = lower_bound(h + 1 + pos, h + 1 + n, h[pos] + df) - h;
if (h[nextPos] == h[pos] + df) {
pos = nextPos;
flag[pos] = 1;
++cnt;
} else {
break;
}
}
if (cnt == n) flag[n] = false, --cnt;
if (checkValid(flag)) {
cout << cnt << '\n';
for (int i = 1; i <= n; ++i) if (flag[i]) cout << h[i] << ' '; cout << '\n';
cout << n - cnt << '\n'; for (int i = 1; i <= n; ++i) if (!flag[i]) cout << h[i] << ' ';
return;
}
}
{ // Case 2: A = {h[1], h[3], ...}, B = {h[2], }
vector<bool> flag(n + 1, false);
int df = h[3] - h[1];
flag[1] = 1;
int pos = 1;
int cnt = 1;
while (pos < n) {
int nextPos = lower_bound(h + 1 + pos, h + 1 + n, h[pos] + df) - h;
if (h[nextPos] == h[pos] + df) {
pos = nextPos;
flag[pos] = 1;
++cnt;
} else {
break;
}
}
if (cnt == n) flag[n] = false, --cnt;
if (checkValid(flag)) {
cout << cnt << '\n';
for (int i = 1; i <= n; ++i) if (flag[i]) cout << h[i] << ' '; cout << '\n';
cout << n - cnt << '\n'; for (int i = 1; i <= n; ++i) if (!flag[i]) cout << h[i] << ' ';
return;
}
}
{ // Case 3: A = {h[2], h[3], ...}, B = {h[1], }
vector<bool> flag(n + 1, false);
int df = h[3] - h[2];
flag[2] = 1;
int pos = 2;
int cnt = 1;
while (pos < n) {
int nextPos = lower_bound(h + 1 + pos, h + 1 + n, h[pos] + df) - h;
if (h[nextPos] == h[pos] + df) {
pos = nextPos;
flag[pos] = 1;
++cnt;
} else {
break;
}
}
if (cnt == n) flag[n] = false, --cnt;
if (checkValid(flag)) {
cout << cnt << '\n';
for (int i = 1; i <= n; ++i) if (flag[i]) cout << h[i] << ' '; cout << '\n';
cout << n - cnt << '\n'; for (int i = 1; i <= n; ++i) if (!flag[i]) cout << h[i] << ' ';
return;
}
}
cout << -1;
}
int main(void) {
ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
if (fopen(task".inp", "r")) {
freopen(task".inp", "r", stdin);
freopen(task".out", "w", stdout);
}
int nTest = 1; if (multiTest) cin >> nTest;
while (nTest--) {
process();
}
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
drvca.cpp: In function 'int main()':
drvca.cpp:120:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
120 | freopen(task".inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
drvca.cpp:121:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
121 | freopen(task".out", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# | 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... |