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
#include<algorithm>
#include<cstdio>
#include<vector>
#include "message.h"
#include "dzialka.h"
using namespace std;
vector <long long> v[75013];
int main()
{
    if (MyNodeId() > 0)
        return 0;
    int n=GetFieldHeight();
    int m=GetFieldWidth();
    long long x;
    long long wyn=0;
    for (int i=0; i<m; i++)
    {
        int k=IsUsableCell(0,i);
        x=k;
        if (i==0)
            v[0].push_back(x);
        else if (x==1)
            v[0].push_back(v[0][i-1]+1);
        else
            v[0].push_back(0);
        wyn+=v[0][i];
    }
    //printf ("%lld\n", wyn);
    for (int i=1; i<n; i++)
    {
        for (int j=0; j<m; j++)
        {
            int k=IsUsableCell(i,j);
            x=k;
            if (x==1)
            {
                if (j!=0)
                    v[i].push_back(v[i][j-1]+1);
                else
                    v[i].push_back(1);
                long long licz=1;
                long long w=v[i][j];
                wyn+=w;
                while (i-licz!=-1&&v[i-licz][j]!=0)
                {
                    w=min(w,v[i-licz][j]);
                    wyn+=w;
                    licz++;
                }
                //printf ("%lld\n", wyn);
            }
            else
                v[i].push_back(0);
        }
    }
    printf ("%lld", wyn);
    return 0;
}