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 <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <unordered_map>
#include <set>
#include <dzialka.h>
#include <message.h>

using namespace std;

typedef long long LL;

LL n, m;
vector<vector<LL>> pre, v;

void makepre()
{
    for(int i = 1; i <= n; i++)
        for(int j = 1; j <= m; j++)
            pre[i][j] = pre[i - 1][j] + pre[i][j - 1] - pre[i - 1][j - 1] + v[i][j];
}

LL solve(int a, int b)
{
    LL cnt = 0;
    for(int i = 0; i < a; i++)
    {
        for(int j = 0; j < b; j++)
        {
            LL ile = pre[a][b] - pre[a - i - 1][b] - pre[a][b - j - 1] + pre[a - i - 1][b - j - 1];
            //cout << a << " " << b << " " << i << " " << j << " " << ile << endl;
            if(ile == (LL)(i + 1) * (LL)(j + 1)) cnt++;
            else break;
        }
    }
    return cnt;
}

int main()
{
    if(MyNodeId() != 0) return 0;
    n = GetFieldHeight();
    m = GetFieldWidth();
    //cin >> n >> m;
    v.resize(n + 7), pre.resize(n + 7);
    for(int i = 0; i <= n + 5; i++)
        v[i].resize(m + 7, 0), pre[i].resize(m + 7, 0);
    for(int i = 0; i < n; i++)
    {
        for(int j = 0; j < m; j++)
        {
            LL czy;
            czy = (LL)IsUsableCell(i, j);
            //cin >> czy;
            v[i + 1][j + 1] = czy;
        }
    }
    makepre();
    LL res = 0;
    for(int i = 1; i <= n; i++)
    {
        for(int j = 1; j <= m; j++)
        {
            if(v[i][j] == 0) continue;
            LL x = solve(i, j);
            res += x;
            //cout << i << " " << j << " " << x << endl;
        }
    }
    printf("%lld", res);
    return 0;
}