Submission #952257

# Submission time Handle Problem Language Result Execution time Memory
952257 2024-03-23T12:03:51 Z ereonzis Drvca (COCI19_drvca) C++17
110 / 110
115 ms 11844 KB
//#pragma GCC optimize("O3")
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
namespace debug {
template <class c> struct rge { c b, e; };
template <class c> rge<c> range(c i, c j) { return rge<c>{i, j}; }
template <class c> char spk(...);
template <class c> auto spk(c *a) -> decltype(cerr << *a, 0);
struct stream {
  ~stream() { cerr << endl; }
  template <class c>
  typename enable_if<sizeof spk<c>(0) != 1, stream &>::type operator<<(c i) {
    cerr << boolalpha << i;
    return *this;
  }
  template <class c>
  typename enable_if<sizeof spk<c>(0) == 1, stream &>::type operator<<(c i) {
    return *this << range(begin(i), end(i));
  }
  template <class a, class b> stream &operator<<(pair<a, b> p) {
    return *this << "(" << p.first << ", " << p.second << ")";
  }
  template <class c> stream &operator<<(rge<c> d) {
    *this << "[";
    for (auto it = d.b; it != d.e; it++)
      *this << ", " + 2 * (it == d.b) << *it;
    return *this << "]";
  }
  stream &_dbg(const string &s, int i, int b) { return *this; }
  template <class c, class... cs>
  stream &_dbg(const string &s, int i, int b, c arg, cs... args) {
    if (i == (int)(s.size()))
      return (*this << ": " << arg);
    b += (s[i] == '(') + (s[i] == '[') + (s[i] == '{') - (s[i] == ')') -
         (s[i] == ']') - (s[i] == '}');
    return (s[i] == ',' && b == 0)
               ? (*this << ": " << arg << "     ")._dbg(s, i + 1, b, args...)
               : (s[i] == ' ' ? *this : *this << s[i])
                     ._dbg(s, i + 1, b, arg, args...);
  }
};
} // namespace debug
#ifdef DEBUG
#define dout debug::stream()
#define dbg(...)                                                               \
  ((dout << "line:" << __LINE__ << " >> ")                                     \
       ._dbg(#__VA_ARGS__, 0, 0, __VA_ARGS__))
#else
#define dout
#define dbg(...)
#endif
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

void PrintAnswer(bool exists, const vector<int> &A, const vector<int> &B) {
  if (!exists) {
    cout << -1 << '\n';
    exit(0);
  }
  cout << A.size() << '\n';
  for (int x : A) {
    cout << x << " ";
  }
  cout << '\n';
  cout << B.size() << '\n';
  for (int x : B) {
    cout << x << " ";
  }
  cout << '\n';
  exit(0);
}

pair<vector<int>, vector<int>>
SplitWithArithmeticSequence(const vector<int> &v, int start, int diff) {
  vector<int> A, B;
  for (int i = 0; i < (int)v.size(); i++) {
    if (v[i] == start) {
      A.push_back(v[i]);
      start += diff;
    } else {
      B.push_back(v[i]);
    }
  }
  return {A, B};
}

void AlignSequences(const vector<int> &A, vector<int> B) {
  multiset<int> elements(A.begin(), A.end()), diffs;
  for (int i = 1; i < (int)A.size(); i++) {
    diffs.insert(A[i] - A[i - 1]);
  }
  while (!B.empty() && *diffs.begin() != *diffs.rbegin()) {
    int b = B.back();
    B.pop_back();
    auto it = elements.insert(b);
    if (it != elements.begin() && next(it) != elements.end()) {
      diffs.erase(diffs.find(*next(it) - *prev(it)));
    }
    if (it != elements.begin()) {
      diffs.insert(*it - *prev(it));
    }
    if (next(it) != elements.end()) {
      diffs.insert(*next(it) - *it);
    }
  }
  if (!B.empty()) {
    PrintAnswer(true, vector<int>(elements.begin(), elements.end()), B);
  }
}

int main() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<int> h(n);
  for (auto &x : h)
    cin >> x;
  sort(h.begin(), h.end());
  if (n == 2) {
    PrintAnswer(true, {h[0]}, {h[1]});
  }
  for (const auto &p :
       {make_pair(h[0], h[1] - h[0]), make_pair(h[0], h[2] - h[0]),
        make_pair(h[1], h[2] - h[1])}) {
    auto [A, B] = SplitWithArithmeticSequence(h, p.first, p.second);
    if (B.empty()) {
      PrintAnswer(true, vector<int>(A.begin(), prev(A.end())), {A.back()});
    }
    AlignSequences(B, A);
  }
  PrintAnswer(false, {}, {});

  return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 600 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 600 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 344 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 1 ms 708 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 29 ms 8180 KB Output is correct
2 Correct 29 ms 8140 KB Output is correct
3 Correct 30 ms 8260 KB Output is correct
4 Correct 29 ms 8148 KB Output is correct
5 Correct 29 ms 8264 KB Output is correct
6 Correct 30 ms 8516 KB Output is correct
7 Correct 29 ms 8160 KB Output is correct
8 Correct 29 ms 8140 KB Output is correct
9 Correct 28 ms 7620 KB Output is correct
10 Correct 30 ms 8140 KB Output is correct
11 Correct 15 ms 3400 KB Output is correct
12 Correct 1 ms 600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 600 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 344 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 1 ms 708 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 29 ms 8180 KB Output is correct
32 Correct 29 ms 8140 KB Output is correct
33 Correct 30 ms 8260 KB Output is correct
34 Correct 29 ms 8148 KB Output is correct
35 Correct 29 ms 8264 KB Output is correct
36 Correct 30 ms 8516 KB Output is correct
37 Correct 29 ms 8160 KB Output is correct
38 Correct 29 ms 8140 KB Output is correct
39 Correct 28 ms 7620 KB Output is correct
40 Correct 30 ms 8140 KB Output is correct
41 Correct 15 ms 3400 KB Output is correct
42 Correct 1 ms 600 KB Output is correct
43 Correct 28 ms 7244 KB Output is correct
44 Correct 95 ms 11844 KB Output is correct
45 Correct 36 ms 9940 KB Output is correct
46 Correct 28 ms 7364 KB Output is correct
47 Correct 115 ms 11720 KB Output is correct
48 Correct 35 ms 9912 KB Output is correct
49 Correct 27 ms 6852 KB Output is correct
50 Correct 78 ms 11648 KB Output is correct
51 Correct 36 ms 10064 KB Output is correct
52 Correct 20 ms 3404 KB Output is correct
53 Correct 95 ms 11792 KB Output is correct
54 Correct 35 ms 10168 KB Output is correct
55 Correct 25 ms 5804 KB Output is correct
56 Correct 18 ms 5268 KB Output is correct
57 Correct 16 ms 3404 KB Output is correct
58 Correct 0 ms 344 KB Output is correct