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
#include <cstdlib>
#include <iostream>
#include <vector>
#include <climits>

#include "krazki.h"
#include "message.h"

using namespace std;

int main() {
  // Tylko zerowy komputer coś liczy.
  int pipeDepth = PipeHeight(), numberOfDisks = NumberOfDiscs();
  if (numberOfDisks > pipeDepth){ 
	  if (MyNodeId() == 0)cout << 0 << endl;
	  return 0;
  }
  vector <long long> disk(numberOfDisks+1);
  vector <long long> R(pipeDepth+1);
  R[0] = LONG_LONG_MAX;
  for(int i = 1; i <= pipeDepth; ++i){
	R[i] = HoleDiameter(i);
	if(R[i] > R[i-1]) R[i] = R[i-1];
	}
  
  disk[0] = 0;
  for(int i = 1; i <= numberOfDisks; ++i){
	  disk[i] = DiscDiameter(i);
	  if (disk[i] < disk[i-1]) disk[i] = disk[i-1];
  }
  int j = pipeDepth;
  for(int i = 1; j > 0 && i <= numberOfDisks;)
	  if(disk[i] > R[j]) j--;
	  else i++, j--;
  		
  if (MyNodeId() == 0)cout << j << endl;
	  return 0;	
  }