1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include <cstdio>
#include <algorithm>
#include "krazki.h"
#include "message.h"
#include <vector>

#define MAXD 109

using namespace std;

typedef long long LL;

vector<LL> holes, disc;

// Just run on one thread, heh.
int main() {
  if (MyNodeId() > 0) return 0;

  int height = PipeHeight();
  int numDiscs = NumberOfDiscs();

  holes.resize(height+1);
  disc.resize(numDiscs+1);
  
  if (numDiscs > height) {
    printf("0\n");
    return 0;
  }
  
  for (int i = 1; i <= height; i++) {
    holes[i] = HoleDiameter(i);

    if (i > 1) holes[i] = min(holes[i], holes[i-1]);
  }

  for (int i = 1; i <= numDiscs; i++) {
    disc[i] = DiscDiameter(i);

    disc[i] = max(disc[i], disc[i-1]);
  }

  int discNum = 1;
  int holeNum = height;

  while (discNum <= numDiscs && holeNum >= (numDiscs - discNum + 1)) {
    if (disc[discNum] <= holes[holeNum]) {
      discNum++;
    }

    if (discNum <= numDiscs) holeNum--;
  }

  printf("%d\n", holeNum);
  
  return 0;
}