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
#include "dzialka.h"
#include "message.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;

ll *pref;
ll **A;

int main() {
	if(MyNodeId() > 0) {
		return 0;
	} else {
		ll height = GetFieldHeight();
		ll width = GetFieldWidth();
		
		pref = new ll[width + 1];
		A = new ll*[width + 1];
		
		for(ll j = 0; j <= width; j++) {
			A[j] = new ll[width + 1];
			for(ll k = 0; k <= width; k++) {
				A[j][k] = 0;
			}
		}
		
		long long res = 0;
		
		for(ll i = 1; i <= height; i++) {
			pref[0] = 0;
			for(ll j = 1; j <= width; j++) {
				pref[j] = pref[j - 1] + IsUsableCell(i - 1, j - 1);
				for(int k = j; k >= 1; k--) {
					if(pref[j] - pref[j - k] == k) {
						A[j][k]++;
						res += A[j][k];
					} else {
						A[j][k] = 0;
					}
				}
			}
		}
		
		cout << res << endl;
		
		for(int j = 0; j <= width; j++) {
			delete [] A[j];
		}
		
		delete [] pref;
		delete [] A;
	}
}