Submission #638230

# Submission time Handle Problem Language Result Execution time Memory
638230 2022-09-05T03:50:49 Z iee Drvca (COCI19_drvca) C++17
0 / 110
112 ms 21580 KB
// iee
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <vector>
#include <set>
#include <map>

#define rep(i, a, b) for (auto i = (a); i <= (b); ++i)
#define per(i, a, b) for (auto i = (a); i >= (b); --i)
#define fi first
#define se second
using ll = long long;
using ull = unsigned long long;
using namespace std;
void work(int);

template <class T> void read(T &x) {
  x = 0; int f = 1, ch = getchar();
  while (!isdigit(ch)) { if (ch == '-') f = -1; ch = getchar(); }
  while (isdigit(ch)) x = x * 10 + (ch - '0'), ch = getchar();
  x *= f;
}

int main() {
  int TT = 1; // cin >> TT;
  rep(CAS, 1, TT)
    work(CAS);
  return 0;
}
const int N = 1e5 + 5;
int n, a[N];
// int jb[N];
// void solve(int A1, int A2) {
  // memset(jb, 0, sizeof jb);
  // const int d = a[A2] - a[A1];
  // jb[A1] = jb[A2] = 1;
  // int las = a[A2];
  // rep(i, A2 + 1, n) {
    // if (a[i] - las == d) {
      // las = a[i];
      // jb[i] = 1;
    // }
  // }
  // vector<int> B;
  // rep(i, 1, n) if (!jb[i]) B.push_back(a[i]);
  // for (int i = 2; i < B.size(); ++i)
    // if (B[i] - B[i - 1] != B[1] - B[0]) return;
  // cout << n - B.size() << '\n';
  // rep(i, 1, n) if (jb[i]) cout << a[i] << ' ';
  // cout << '\n' << B.size() << '\n';
  // for (int x: B) cout << x << ' ';
  // exit(0);
// }
void solve(int A1, int A2) {
  multiset<int> B, dB;
  rep(i, 1, n) if (i != A1 && i != A2) B.emplace(a[i]);
  vector<int> A{a[A1], a[A2]};
  int las = -1, d = a[A2] - a[A1];
  for (int v: B) {
    if (las != -1) dB.emplace(v - las);
    las = v;
  }
  int curA = a[A2] + d;
  while (A.size() < n) {
    if (*dB.begin() == *prev(dB.end())) {
      cout << A.size() << '\n';
      for (int x: A) cout << x << ' ';
      cout << '\n' << B.size() << '\n';
      for (int x: B) cout << x << ' ';
      exit(0);
    }
    auto it = B.find(curA);
    if (it == B.end()) return;
    if (it != B.begin()) dB.erase(dB.find(curA - *prev(it)));
    if (next(it) != B.end()) dB.erase(dB.find(*next(it) - curA));
    B.erase(B.find(curA));
    A.push_back(curA);
    curA += d;
  }
}
void work(int CASE) {
  cin >> n;
  rep(i, 1, n) cin >> a[i];
  sort(a + 1, a + n + 1);
  if (n == 2) {
    cout << 1 << '\n' << a[1] << '\n' << 1 << '\n' << a[2];
    return;
  }
  if ([&]() { rep(i, 2, n) if (a[i] - a[i - 1] != a[2] - a[1]) return 0; return 1; }()) {
    cout << n - 1 << '\n';
    rep(i, 1, n - 1) cout << a[i] << ' ';
    cout << '\n' << 1 << '\n' << a[n];
    return;
  }
  solve(1, 2), solve(2, 3), solve(1, 3);
  puts("-1");
}

Compilation message

drvca.cpp: In function 'void solve(int, int)':
drvca.cpp:66:19: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   66 |   while (A.size() < n) {
      |          ~~~~~~~~~^~~
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 105 ms 12212 KB Output is correct
2 Correct 103 ms 11996 KB Output is correct
3 Correct 112 ms 12188 KB Output is correct
4 Correct 97 ms 12004 KB Output is correct
5 Runtime error 100 ms 21580 KB Execution killed with signal 6
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -