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
// Lupus Nocawy 25 XI 2016, PA2016
// http://potyczki.mimuw.edu.pl/
// Runda 4
// Zadanie: KRA
// Krążki 2 [B]

#include <cstdio>
#include <iostream>
#include <cassert>
#include <algorithm>
#include <vector>
#include <deque>
#include <queue>
using namespace std;
#define REP(i,n) for(int i=0, _n=n; i<_n; ++i)
#define FOR(i,a,b) for(int i=(a), _b=(b); i<=_b; ++i)
#define FORD(i,a,b) for(int i=(a), _b=(b); i>=_b; --i)
#define IT(i,x) __typeof__(x) i=x
#define MP make_pair
#define PB push_back
typedef long long int lli;
typedef unsigned long long int llu;
typedef pair<int,int> pii;
typedef pair<lli,int> pllii;
const int debug=1;

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

int main() {
  if (MyNodeId() != 0) {
    // Tylko zerowy komputer coś liczy.
    return EXIT_SUCCESS;
  }

  int depth = PipeHeight();
  priority_queue<pllii, vector<pllii>, greater<pllii> > Q;

  FOR(i,1,depth)
    Q.push(MP(HoleDiameter(i),i));

  int result = depth+1;
  int discs = NumberOfDiscs();
  FOR(i,1,discs){
    int d = DiscDiameter(i);
    while (!Q.empty() && ( Q.top().first < d || Q.top().second >= result) ){
      result = min(Q.top().second, result);
      Q.pop();
    }
    result--;
  }

  result = max(result,0);
  printf("%d\n", result);
  return EXIT_SUCCESS;
}