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
// Arkadiusz Roussau
// PA2017 Dzialka 2 [B]
#include <iostream>

#include "dzialka.h"
#include "message.h"

using namespace std;

const int MAX_SIZE = 3100;
const int MAIN_NODE = 0;

int width;
int height;
long long results[MAX_SIZE][MAX_SIZE];

long long solve(int height, int width) {
  for (int i = width - 1; i >= 0; i--) {
    for (int j = height - 1; j >= 0; j--) {
      if (IsUsableCell(j, i)) {
	results[i][j] = results[i + 1][j] + results[i][j + 1];
	results[i][j]++;
	
	if (results[i + 1][j] || results[i][j + 1]) {
	  results[i][j] -= results[i + 1][j + 1];
	}
      }
    }
  }
  
  for (int i = width - 1; i >= 0; i--) {
    for (int j = height - 1; j >= 0; j--) {
      if (IsUsableCell(j,i)) {
	results[i][j] += results[i + 1][j] + results[i][j + 1];
	results[i][j] -= results[i + 1][j + 1];
      }
        else {
        results[i][j] = results[i + 1][j] + results[i][j + 1] - results[i + 1][j + 1];       
}
    }
  }
  
  return results[0][0];
}

int main() {
  ios_base::sync_with_stdio(0);
  
  if (MyNodeId() == MAIN_NODE) {
    height = GetFieldHeight();
    width = GetFieldWidth();
    cout << solve(height, width) << "\n";
  }
  
  return 0;
}