Submission #197980

# Submission time Handle Problem Language Result Execution time Memory
197980 2020-01-24T12:39:03 Z model_code Drvca (COCI19_drvca) C++17
110 / 110
255 ms 11476 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef double lf;
typedef long double Lf;
typedef pair <int,int> pii;
typedef pair <ll, ll> pll;

#define TRACE(x) cerr << #x << "  " << x << endl
#define FOR(i, a, b) for (int i = (a); i < int(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define _ << " " <<

#define fi first
#define sec second
#define mp make_pair
#define pb push_back

const int MAXN = 100100;

int n, p[MAXN];

void print(vector <int> &a, multiset <int> &b) {
  printf("%d\n", (int)a.size());
  for (auto x : a) printf("%d ", x);
  puts("");
  printf("%d\n", (int)b.size());
  for (auto x : b) printf("%d ", x);
  puts("");
}

void check(int a, int b) {
  multiset <int> s, raz;
  int k = b - a;
  REP(i, n) s.insert(p[i]);
  s.erase(s.find(a));
  s.erase(s.find(b));

  vector <int> ans;
  ans.pb(a);
  ans.pb(b);

  int last = -1;
  for (auto x : s) {
    if (last != -1) raz.insert(x - last);
    last = x;
  }

  int tmp = b + k;
  do {
    if (*raz.begin() == *raz.rbegin()) {
      print(ans, s);
      exit(0);  
    }

    auto it = s.find(tmp);
    if (it == s.end()) break;
    auto l = it;
    auto r = it;
    if (it != s.begin()) {
      l--;
      raz.erase(raz.find(*it - *l));
    }
    r++;
    if (r != s.end()) {
      raz.erase(raz.find(*r - *it));
      if (it != s.begin()) raz.insert(*r - *l);
    }
    s.erase(it);
    ans.pb(tmp);
    tmp += k;
  } while ((int)ans.size() < n);
}

int main() {
  scanf("%d",&n);
  REP(i, n) scanf("%d",&p[i]);
  sort(p, p + n);

  if (n <= 4) {
    printf("%d\n",n / 2);
    REP(i, n / 2) printf("%d ",p[i]);
    puts("");
    printf("%d\n",n - n / 2);
    FOR(i, n / 2, n) printf("%d ",p[i]);
    puts("");
    return 0;
  }

  check(p[0], p[1]);
  check(p[0], p[2]);
  check(p[1], p[2]);

  puts("-1");

  return 0;
}

Compilation message

drvca.cpp: In function 'int main()':
drvca.cpp:78:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d",&n);
   ~~~~~^~~~~~~~~
drvca.cpp:79:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   REP(i, n) scanf("%d",&p[i]);
             ~~~~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 348 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 2 ms 380 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 256 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 268 KB Output is correct
12 Correct 2 ms 252 KB Output is correct
13 Correct 2 ms 256 KB Output is correct
14 Correct 2 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 348 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 2 ms 380 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 256 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 268 KB Output is correct
12 Correct 2 ms 252 KB Output is correct
13 Correct 2 ms 256 KB Output is correct
14 Correct 2 ms 348 KB Output is correct
15 Correct 3 ms 376 KB Output is correct
16 Correct 3 ms 376 KB Output is correct
17 Correct 3 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 3 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 376 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 380 KB Output is correct
29 Correct 2 ms 376 KB Output is correct
30 Correct 2 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 129 ms 11476 KB Output is correct
2 Correct 101 ms 11128 KB Output is correct
3 Correct 138 ms 11460 KB Output is correct
4 Correct 103 ms 11256 KB Output is correct
5 Correct 142 ms 11428 KB Output is correct
6 Correct 102 ms 11220 KB Output is correct
7 Correct 130 ms 11444 KB Output is correct
8 Correct 101 ms 11128 KB Output is correct
9 Correct 102 ms 10928 KB Output is correct
10 Correct 114 ms 11128 KB Output is correct
11 Correct 88 ms 11128 KB Output is correct
12 Correct 3 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 348 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 2 ms 380 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 256 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 268 KB Output is correct
12 Correct 2 ms 252 KB Output is correct
13 Correct 2 ms 256 KB Output is correct
14 Correct 2 ms 348 KB Output is correct
15 Correct 3 ms 376 KB Output is correct
16 Correct 3 ms 376 KB Output is correct
17 Correct 3 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 3 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 376 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 380 KB Output is correct
29 Correct 2 ms 376 KB Output is correct
30 Correct 2 ms 256 KB Output is correct
31 Correct 129 ms 11476 KB Output is correct
32 Correct 101 ms 11128 KB Output is correct
33 Correct 138 ms 11460 KB Output is correct
34 Correct 103 ms 11256 KB Output is correct
35 Correct 142 ms 11428 KB Output is correct
36 Correct 102 ms 11220 KB Output is correct
37 Correct 130 ms 11444 KB Output is correct
38 Correct 101 ms 11128 KB Output is correct
39 Correct 102 ms 10928 KB Output is correct
40 Correct 114 ms 11128 KB Output is correct
41 Correct 88 ms 11128 KB Output is correct
42 Correct 3 ms 376 KB Output is correct
43 Correct 120 ms 11368 KB Output is correct
44 Correct 255 ms 10448 KB Output is correct
45 Correct 95 ms 10872 KB Output is correct
46 Correct 104 ms 11088 KB Output is correct
47 Correct 227 ms 10336 KB Output is correct
48 Correct 93 ms 10872 KB Output is correct
49 Correct 117 ms 11432 KB Output is correct
50 Correct 209 ms 10280 KB Output is correct
51 Correct 94 ms 10872 KB Output is correct
52 Correct 105 ms 11040 KB Output is correct
53 Correct 229 ms 10544 KB Output is correct
54 Correct 95 ms 10744 KB Output is correct
55 Correct 107 ms 11036 KB Output is correct
56 Correct 96 ms 11248 KB Output is correct
57 Correct 85 ms 11100 KB Output is correct
58 Correct 2 ms 256 KB Output is correct