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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#include <vector>
#include <iostream>
#include <algorithm>

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


#define LOG_ENABLED false

#define LOG if (LOG_ENABLED) cerr
typedef long long ll;
typedef unsigned long long ull;

const ll PARALLEL_TRIGGER = 30000000;
const ll INF = 1000000000000000009LL;


using namespace std;


void solveInSingle()
{
    int pipeHeight = PipeHeight();
    int numberOfDisc = NumberOfDiscs();
    vector<ll> minHoleWidths = vector<ll>(pipeHeight + 1);
    
    minHoleWidths[1] = HoleDiameter(1);
    for (int i = 2; i <= pipeHeight; i++)
    {
        minHoleWidths[i] = min(minHoleWidths[i - 1], HoleDiameter(i));
    }
    
    int currentDepth = pipeHeight + 1;
    
    for (int i = 1; i <= numberOfDisc; i++)
    {
        if (numberOfDisc - i + 1 > currentDepth - 1)
        {
            currentDepth = 0;
            break;
        }
        
        ll discWidth = DiscDiameter(i);
        currentDepth --;
        while (currentDepth > 0 && minHoleWidths[currentDepth] < discWidth)
        {
            currentDepth --;
        }
        
        LOG << "disc: " << i << ", depth: " << currentDepth << endl;
    }
    
    cout << currentDepth;
}


int main()
{
    int pipeHeight = PipeHeight();
    int numberOfDisc = NumberOfDiscs();
    
    if (pipeHeight + numberOfDisc <= PARALLEL_TRIGGER)
    {
        if (MyNodeId() == 0)
        {
            solveInSingle();
        }
        return 0;
    }
    
    return 0;
}