/*
Author: duxp
Version: 1
Created at: 2025-12-30 21:43
*/
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define all(x) x.begin() + 1, x.end()
#define nall(x) x.begin(), x.end()
#define vi vector<int>
#define pll pair<ll, ll>
#define pii pair<int, int>
#define fi first
#define se second
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define debug(x) cerr << #x << " = " << (x) << endl
#define debug2(x, y) cerr << #x << " = " << (x) << ", " << #y << " = " << (y) << endl
#define debug3(x, y, z) cerr << #x << " = " << (x) << ", " << #y << " = " << (y) << ", " << #z << " = " << (z) << endl
#define trailingzero(x) __builtin_ctzll(x)
#define cntbit1(x) __builtin_popcountll(x)
#define leadingzero(x) __builtin_clzll(x)
#define TDN signed main()
#define KILL() exit(0)
#define NAME "task"
template <typename T>
inline int getbit(T x, int k) { return (x >> k) & 1; }
template <typename T>
inline T onbit(T x, int k) { return x | (T(1) << k); }
template <typename T>
inline T offbit(T x, int k) { return x & ~(T(1) << k); }
template <typename T>
inline bool minimize(T &a, const T &b) {
if (a > b) { a = b; return true; }
return false;
}
template <typename T>
inline bool maximize(T &a, const T &b) {
if (a < b) { a = b; return true; }
return false;
}
const ll INF = 1e18;
const int MOD = 1000000007;
const int MOD2 = 998244353;
const int MAXN = 200000;
const int MAX_SUB23 = 2000;
namespace sub23 {
bool check(const vi& v) {
if (v.empty() || v.size() == 1) return true;
int d = v[1] - v[0];
for (int i = 2; i < (int)v.size(); i++)
if (v[i] - v[i - 1] != d) return false;
return true;
}
void output(const vi& A, const vi& B) {
cout << A.size() << "\n";
for (int i = 0; i < (int)A.size(); i++) cout << A[i] << (i == (int)A.size() - 1 ? "" : " ");
cout << "\n";
cout << B.size() << "\n";
for (int i = 0; i < (int)B.size(); i++) cout << B[i] << (i == (int)B.size() - 1 ? "" : " ");
cout << "\n";
exit(0);
}
bool ok(int n) {
return n <= MAX_SUB23;
}
void try_build(int n, const vi& a, int idx1, int idx2) {
int d = a[idx2] - a[idx1];
vi cand_indices;
int last = a[idx1];
cand_indices.push_back(idx1);
for (int i = idx1 + 1; i <= n; i++) {
if (a[i] == last + d) {
cand_indices.push_back(i);
last = a[i];
}
}
for (int len = 1; len <= (int)cand_indices.size(); len++) {
vi A, B;
vector<bool> inA(n + 1, false);
for (int i = 0; i < len; i++) inA[cand_indices[i]] = true;
for (int i = 1; i <= n; i++) {
if (inA[i]) A.pb(a[i]);
else B.pb(a[i]);
}
if (check(B)) output(A, B);
}
}
void solve(int n, vi& a) {
if (n == 1) {
cout << "1\n" << a[1] << "\n0\n\n";
exit(0);
}
vi A_s = {a[1]}, B_s;
for (int i = 2; i <= n; i++) B_s.pb(a[i]);
if (check(B_s)) output(A_s, B_s);
try_build(n, a, 1, 2);
if (n >= 3) {
try_build(n, a, 1, 3);
try_build(n, a, 2, 3);
}
cout << -1;
exit(0);
}
}
TDN
{
fast;
string fname = string(NAME);
if (fopen((fname + ".inp").c_str(), "r")) {
freopen((fname + ".inp").c_str(), "r", stdin);
freopen((fname + ".out").c_str(), "w", stdout);
}
int n;cin>>n;
vi a(n + 1);
for (int i = 1; i <= n; i++) cin >> a[i];
sort(all(a));
if (sub23::ok(n)) {
sub23::solve(n, a);
}
KILL();
}
컴파일 시 표준 에러 (stderr) 메시지
drvca.cpp: In function 'int main()':
drvca.cpp:131:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
131 | freopen((fname + ".inp").c_str(), "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
drvca.cpp:132:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
132 | freopen((fname + ".out").c_str(), "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... |