이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define fast ios::sync_with_stdio(0);cin.tie(0)
typedef long long ll;
#define f first
#define s second
#define LOGN 21
const ll MOD = 1e9 + 7;
const ll MAXN = 2e5 + 100;
multiset<int> other_sequence, diff;
vector<int> h, sequence;
int cnt = 0;
void omit(int k) {
auto u = other_sequence.lower_bound(k);
int C = 0;
if (u != other_sequence.begin()) {
C++;
int dd = *u - *prev(u);
diff.erase(diff.find(dd));
if (diff.count(dd) == 0)
cnt--;
}
if (prev(other_sequence.end()) != u) {
C++;
int x = *u;
u++;
int dd = *u - x;
u--;
diff.erase(diff.find(dd));
if (diff.count(dd) == 0)
cnt--;
}
if (C == 2) {
int L = *prev(u);
u++;
int R = *u;
u--;
diff.insert(R - L);
if (diff.count(R - L) == 1)
cnt++;
}
other_sequence.erase(u);
}
int main() {
fast;
int N;
cin >> N;
h = vector<int>(N+1, 0);
for (int i = 1; i <= N; i++)
cin >> h[i];
sort(h.begin(), h.end());
if (N == 2) {
cout << "1\n";
cout << h[1] << "\n";
cout << "1\n";
cout << h[2] << "\n";
exit(0);
}
for (int i = 1; i <= 2; i++) {
for (int j = i+1; j <= 3; j++) {
diff.clear();
other_sequence.clear();
sequence.clear();
cnt = 0;
for (int q = 1; q <= N; q++) {
other_sequence.insert(h[q]);
if (q != 1)
diff.insert(h[q] - h[q-1]);
}
int last = -1;
for (auto u : diff) {
cnt += (last != u);
last = u;
}
omit(h[i]);
omit(h[j]);
sequence.push_back(h[i]);
sequence.push_back(h[j]);
if (cnt <= 1) {
if (other_sequence.size() == 0) {
other_sequence.insert(sequence.back());
sequence.pop_back();
}
cout << sequence.size() << "\n";
for (auto u : sequence)
cout << u << " ";
cout << "\n";
cout << other_sequence.size() << "\n";
for (auto u : other_sequence)
cout << u << " ";
cout << "\n";
exit(0);
}
int seq_diff = sequence[1] - sequence[0];
while (true) {
int potential_new = sequence.back() + seq_diff;
if (other_sequence.count(potential_new) == 0)
break;
omit(potential_new);
sequence.push_back(potential_new);
if (cnt <= 1) {
if (other_sequence.size() == 0) {
other_sequence.insert(sequence.back());
sequence.pop_back();
}
cout << sequence.size() << "\n";
for (auto u : sequence)
cout << u << " ";
cout << "\n";
cout << other_sequence.size() << "\n";
for (auto u : other_sequence)
cout << u << " ";
cout << "\n";
exit(0);
}
}
}
}
cout << "-1\n";
}
# | 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... |