Submission #198338

#TimeUsernameProblemLanguageResultExecution timeMemory
198338alradDrvca (COCI19_drvca)C++17
0 / 110
3 ms632 KiB
#include <bits/stdc++.h> using namespace std; int main() { ios_base :: sync_with_stdio(0); cin.tie(0) , cout.tie(0); int n; cin >> n; assert(n <= 300); vector<long long> a(n); for (int i = 0; i < n; i++) { cin >> a[i]; } sort(a.begin() , a.end()); if (n == 2) { cout << 1 << '\n' << a[0] << '\n'; cout << 1 << '\n' << a[1] << '\n'; return 0; } auto run = [&](int x , int y) { int d1 = a[y] - a[x] , p1 = a[y]; vector<int> seq1 , seq2; seq1.push_back(a[x]); seq1.push_back(a[y]); for (int i = 0; i < n; i++) { if (i == x || i == y) { continue; } if (a[i] - p1 == d1) { seq1.push_back(a[i]); p1 = a[i]; } else { seq2.push_back(a[i]); } } bool good = true; if ((int)seq2.size() >= 2) { for (int i = 1; i < (int)seq2.size() && good; i++) { if (seq2[1] - seq2[0] != seq2[i] - seq2[i - 1]) { good = false; } } } if (!good) { //try to make good multiset<int> q1 , q2; for (int num : seq1) { q1.insert(num); } int d2 = seq2[1] - seq2[0]; for (int num : seq2) { q2.insert(num); } good = true; for (int num : q2) { if (num == *prev(q2.end())) { continue; } if (q2.count(num + d2) == 0) { auto it = q1.find(num + d2); if (it == prev(q1.end())) { q2.insert(*it); q1.erase(it); } else { good = false; } } } if (good) { cout << (int)q1.size() << '\n'; for (int num : q1) { cout << num << " "; } cout << '\n'; cout << (int)q2.size() << '\n'; for (int num : q2) { cout << num << " "; } cout << '\n'; exit(0); } } if (good) { if (seq2.empty()) { seq2.push_back(seq1.back()); seq1.pop_back(); } cout << (int)seq1.size() << '\n'; for (int num : seq1) { cout << num << " "; } cout << '\n'; cout << (int)seq2.size() << '\n'; for (int num : seq2) { cout << num << " "; } cout << '\n'; exit(0); } }; run(0 , 1); run(0 , 2); run(1 , 2); cout << -1 << '\n'; 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...