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
//Lukasz Janeczko Krakow
#include <iostream>
#include <vector>
#include <algorithm>
#include "krazki.h"
#include "message.h"
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    if(MyNodeId()==0)
        {
            int n, m;
            n=PipeHeight();
            m=NumberOfDiscs();
            int last=n-1; long long fir=DiscDiameter(1ll);
            vector <long long> T(n);
            T[0]=HoleDiameter(1ll);
            if(T[0]<fir)
                last=-1;
            for(long long i=1; i<n && last==n-1; i++)
                {
                    T[i]=min(HoleDiameter(i+1),T[i-1]);
                    if(T[i]<fir)
                        last=i-1;
                }
            bool bad=false; int l, r, s;
            if(last<0)
                bad=true;
            else
                T[last]=0;
            for(long long j=2; j<=m && !bad; j++)
                {
                    fir=DiscDiameter(j);
                    l=0;
                    r=last;
                    while(l!=r)
                        {
                            s=(l+r)/2;
                            if(T[s]<fir)
                                r=s;
                            else
                                l=s+1;
                        }
                    if(l==0)
                        bad=true;
                    else
                        {
                            last=l-1;
                            T[l-1]=0;
                        }
                    //cout << last <<  " " << fir << " " << l <<  " " << r <<  " " <<endl;
                }
            if(bad)
                cout << 0 <<endl;
            else
                cout << last+1 <<endl;
        }
    return 0;
}