Submission #198346

# Submission time Handle Problem Language Result Execution time Memory
198346 2020-01-25T16:35:51 Z alrad Drvca (COCI19_drvca) C++17
50 / 110
7 ms 556 KB
#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;
         multiset<int> erased;
         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 == q1.end()) {
                  good = false;
                  break;
               }
               while (it != q1.end()) {
                  q2.insert(*it);
                  erased.insert(*it);
                  it++;
               }
               break;
            }
         }
         if (good) {
            cout << (int)q1.size() - (int)erased.size() << '\n';
            for (int num : q1) {
               auto w = erased.find(num);
               if (w == erased.end())
                  cout <<  num << " ";
               else
                  erased.erase(w);
            }
            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 time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 3 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 380 KB Output is correct
12 Correct 3 ms 376 KB Output is correct
13 Correct 3 ms 476 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 3 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 380 KB Output is correct
12 Correct 3 ms 376 KB Output is correct
13 Correct 3 ms 476 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 504 KB Output is correct
16 Correct 7 ms 420 KB Output is correct
17 Correct 2 ms 352 KB Output is correct
18 Correct 2 ms 380 KB Output is correct
19 Correct 4 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 2 ms 376 KB Output is correct
23 Correct 2 ms 376 KB Output is correct
24 Correct 2 ms 376 KB Output is correct
25 Correct 2 ms 380 KB Output is correct
26 Correct 2 ms 376 KB Output is correct
27 Correct 2 ms 376 KB Output is correct
28 Correct 2 ms 376 KB Output is correct
29 Correct 2 ms 376 KB Output is correct
30 Correct 2 ms 504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 3 ms 556 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 3 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 380 KB Output is correct
12 Correct 3 ms 376 KB Output is correct
13 Correct 3 ms 476 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 504 KB Output is correct
16 Correct 7 ms 420 KB Output is correct
17 Correct 2 ms 352 KB Output is correct
18 Correct 2 ms 380 KB Output is correct
19 Correct 4 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 2 ms 376 KB Output is correct
23 Correct 2 ms 376 KB Output is correct
24 Correct 2 ms 376 KB Output is correct
25 Correct 2 ms 380 KB Output is correct
26 Correct 2 ms 376 KB Output is correct
27 Correct 2 ms 376 KB Output is correct
28 Correct 2 ms 376 KB Output is correct
29 Correct 2 ms 376 KB Output is correct
30 Correct 2 ms 504 KB Output is correct
31 Runtime error 3 ms 556 KB Execution killed with signal 11 (could be triggered by violating memory limits)
32 Halted 0 ms 0 KB -