답안 #235679

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
235679 2020-05-29T10:08:30 Z doowey Drvca (COCI19_drvca) C++14
110 / 110
116 ms 8432 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

#define fi first
#define se second
#define mp make_pair
#define fastIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int N = (int)1e5 + 10;
int hh[N];
bool ok[N];
int n;

void print_solution(vector<int> A, vector<int> B){
  if(B.empty()){
    B.push_back(A.back());
    A.pop_back();
  }
  cout << A.size() << "\n";
  for(auto x : A) cout << x << " ";
  cout << "\n";
  cout << B.size() << "\n";
  for(auto x : B) cout << x << " ";
  cout << "\n";
  exit(0);
}

int bad;

struct F : multiset<int>{
  bool good(iterator it){
    auto nx = it;
    nx ++ ;
    if(nx == end() || it == begin()) return true;
    auto pv = it;
    pv -- ;
    return ((*it) - (*pv))==((*nx) - (*it));
  }
  void add(int x){
    if(size() < 2){
      insert(x);
      return;
    }
    auto it = insert(x);
    it -- ;
    bad += !good(it);
  }
  void rem(int x){
    auto it = lower_bound(x);
    bad -= !good(it);
    auto pv = it; 
    if(pv != begin()){
      pv -- ;
      bad -= !good(pv);
    }
    auto nx = it;
    if(nx != end()){
      nx ++ ;
      if(nx != end()){
        bad -= !good(nx);
      }
    }
    it = erase(it);
    if(it != end()){
      bad += !good(it);
    }
    if(it != begin()){
      it -- ;
      bad += !good(it);
    }
  }
};

F cur;

int main(){
  fastIO;
  cin >> n;
  for(int i = 0 ; i < n; i ++ ) 
    cin >> hh[i];
  sort(hh, hh + n);
  if(n == 2){
    cout << 1 << "\n" << hh[0] << "\n" << 1 << "\n" << hh[1] << "\n";
    return 0;
  }
  if(n == 3){
    cout << 2 << "\n" << hh[0] << " " << hh[1] << "\n" << 1 << "\n" << hh[2] << "\n";
    return 0;
  }
  if(n == 4){
    cout << 2 << "\n" << hh[0] << " " << hh[1] << "\n" << 2 << "\n" << hh[2] << " " << hh[3] << "\n";
    return 0;
  }
  int el, dif;
  for(int ii = 0 ; ii < 3; ii ++ ){
    for(int jj = ii + 1; jj < 3; jj ++ ){
      dif = hh[jj] - hh[ii];
      el = hh[jj] + dif;
      bad = 0;
      cur.clear();
      for(int x = 0 ;x < n; x ++ ){
        if(x == ii || x == jj) continue;
        cur.add(hh[x]);
      }
      vector<int> cc = {hh[ii], hh[jj]};
      vector<int> dd;
      if(bad == 0){
        for(auto p : cur) dd.push_back(p);
        print_solution(cc,dd);
      }
      for(int x = jj + 1; x < n ; x ++ ){
        if(hh[x] == el){
          cc.push_back(hh[x]);
          cur.rem(hh[x]);
          if(bad == 0){
            for(auto p : cur){
              dd.push_back(p);
            }
            print_solution(cc,dd);
          }
          el += dif;
        }
      }
      
    }
  }
  cout << -1 << "\n";
  return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 4 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 4 ms 384 KB Output is correct
10 Correct 5 ms 256 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 4 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 4 ms 384 KB Output is correct
10 Correct 5 ms 256 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
19 Correct 5 ms 384 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
21 Correct 5 ms 384 KB Output is correct
22 Correct 5 ms 384 KB Output is correct
23 Correct 5 ms 384 KB Output is correct
24 Correct 5 ms 384 KB Output is correct
25 Correct 5 ms 384 KB Output is correct
26 Correct 5 ms 384 KB Output is correct
27 Correct 5 ms 384 KB Output is correct
28 Correct 5 ms 384 KB Output is correct
29 Correct 5 ms 384 KB Output is correct
30 Correct 5 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 65 ms 7416 KB Output is correct
2 Correct 63 ms 6520 KB Output is correct
3 Correct 68 ms 7412 KB Output is correct
4 Correct 60 ms 6520 KB Output is correct
5 Correct 67 ms 7412 KB Output is correct
6 Correct 59 ms 6392 KB Output is correct
7 Correct 65 ms 7416 KB Output is correct
8 Correct 59 ms 6520 KB Output is correct
9 Correct 58 ms 6136 KB Output is correct
10 Correct 60 ms 6904 KB Output is correct
11 Correct 50 ms 7408 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 4 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 4 ms 384 KB Output is correct
10 Correct 5 ms 256 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
19 Correct 5 ms 384 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
21 Correct 5 ms 384 KB Output is correct
22 Correct 5 ms 384 KB Output is correct
23 Correct 5 ms 384 KB Output is correct
24 Correct 5 ms 384 KB Output is correct
25 Correct 5 ms 384 KB Output is correct
26 Correct 5 ms 384 KB Output is correct
27 Correct 5 ms 384 KB Output is correct
28 Correct 5 ms 384 KB Output is correct
29 Correct 5 ms 384 KB Output is correct
30 Correct 5 ms 384 KB Output is correct
31 Correct 65 ms 7416 KB Output is correct
32 Correct 63 ms 6520 KB Output is correct
33 Correct 68 ms 7412 KB Output is correct
34 Correct 60 ms 6520 KB Output is correct
35 Correct 67 ms 7412 KB Output is correct
36 Correct 59 ms 6392 KB Output is correct
37 Correct 65 ms 7416 KB Output is correct
38 Correct 59 ms 6520 KB Output is correct
39 Correct 58 ms 6136 KB Output is correct
40 Correct 60 ms 6904 KB Output is correct
41 Correct 50 ms 7408 KB Output is correct
42 Correct 5 ms 384 KB Output is correct
43 Correct 65 ms 7648 KB Output is correct
44 Correct 116 ms 6876 KB Output is correct
45 Correct 56 ms 7160 KB Output is correct
46 Correct 61 ms 7488 KB Output is correct
47 Correct 95 ms 6936 KB Output is correct
48 Correct 54 ms 7160 KB Output is correct
49 Correct 62 ms 7416 KB Output is correct
50 Correct 86 ms 6520 KB Output is correct
51 Correct 58 ms 7164 KB Output is correct
52 Correct 61 ms 7416 KB Output is correct
53 Correct 102 ms 6660 KB Output is correct
54 Correct 58 ms 7160 KB Output is correct
55 Correct 63 ms 7544 KB Output is correct
56 Correct 65 ms 7416 KB Output is correct
57 Correct 50 ms 8432 KB Output is correct
58 Correct 5 ms 384 KB Output is correct