Submission #197982

# Submission time Handle Problem Language Result Execution time Memory
197982 2020-01-24T12:39:27 Z model_code Drvca (COCI19_drvca) C++17
110 / 110
276 ms 11684 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[2]);
  check(p[0], p[1]);
  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 6 ms 376 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 2 ms 248 KB Output is correct
6 Correct 2 ms 256 KB Output is correct
7 Correct 2 ms 256 KB Output is correct
8 Correct 3 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 256 KB Output is correct
12 Correct 2 ms 256 KB Output is correct
13 Correct 2 ms 256 KB Output is correct
14 Correct 2 ms 252 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 376 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 2 ms 248 KB Output is correct
6 Correct 2 ms 256 KB Output is correct
7 Correct 2 ms 256 KB Output is correct
8 Correct 3 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 256 KB Output is correct
12 Correct 2 ms 256 KB Output is correct
13 Correct 2 ms 256 KB Output is correct
14 Correct 2 ms 252 KB Output is correct
15 Correct 3 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 3 ms 380 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 248 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 0 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 249 ms 11532 KB Output is correct
2 Correct 159 ms 10360 KB Output is correct
3 Correct 214 ms 11600 KB Output is correct
4 Correct 165 ms 10364 KB Output is correct
5 Correct 239 ms 11540 KB Output is correct
6 Correct 161 ms 10308 KB Output is correct
7 Correct 234 ms 11372 KB Output is correct
8 Correct 159 ms 10376 KB Output is correct
9 Correct 156 ms 10884 KB Output is correct
10 Correct 174 ms 11400 KB Output is correct
11 Correct 82 ms 11248 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 376 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 2 ms 248 KB Output is correct
6 Correct 2 ms 256 KB Output is correct
7 Correct 2 ms 256 KB Output is correct
8 Correct 3 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 256 KB Output is correct
12 Correct 2 ms 256 KB Output is correct
13 Correct 2 ms 256 KB Output is correct
14 Correct 2 ms 252 KB Output is correct
15 Correct 3 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 3 ms 380 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 248 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 0 ms 376 KB Output is correct
31 Correct 249 ms 11532 KB Output is correct
32 Correct 159 ms 10360 KB Output is correct
33 Correct 214 ms 11600 KB Output is correct
34 Correct 165 ms 10364 KB Output is correct
35 Correct 239 ms 11540 KB Output is correct
36 Correct 161 ms 10308 KB Output is correct
37 Correct 234 ms 11372 KB Output is correct
38 Correct 159 ms 10376 KB Output is correct
39 Correct 156 ms 10884 KB Output is correct
40 Correct 174 ms 11400 KB Output is correct
41 Correct 82 ms 11248 KB Output is correct
42 Correct 2 ms 376 KB Output is correct
43 Correct 199 ms 11508 KB Output is correct
44 Correct 276 ms 10560 KB Output is correct
45 Correct 142 ms 10988 KB Output is correct
46 Correct 168 ms 10932 KB Output is correct
47 Correct 223 ms 10360 KB Output is correct
48 Correct 138 ms 10944 KB Output is correct
49 Correct 205 ms 11456 KB Output is correct
50 Correct 203 ms 10268 KB Output is correct
51 Correct 148 ms 10924 KB Output is correct
52 Correct 186 ms 11556 KB Output is correct
53 Correct 222 ms 10380 KB Output is correct
54 Correct 142 ms 10920 KB Output is correct
55 Correct 179 ms 11684 KB Output is correct
56 Correct 97 ms 11048 KB Output is correct
57 Correct 82 ms 11220 KB Output is correct
58 Correct 2 ms 376 KB Output is correct