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
#include "dzialka.h"
#include "message.h"
#include <iostream>

long long GetFieldH(int r,int c,int cn){
   long long s=0;
   while(c<cn && IsUsableCell(r,c)==1){
      s++;
      c++;
   }
   return s;
}

long long GetFieldV(int r,int c,int rn){
   long long s=-1;
   while(r<rn && IsUsableCell(r,c)==1){
      s++;
      r++;
   }
   if(s==-1)return 0;
   else return s;
}



int main() {
  const int NumRows = GetFieldHeight();
  const int NumCols = GetFieldWidth();
  long long Fields = 0;


  for (int Row=0; Row < NumRows; Row++){
    for (int Col=MyNodeId(); Col < NumCols; Col+=NumberOfNodes()){
      Fields+=GetFieldH(Row,Col,NumCols);
      Fields+=GetFieldV(Row,Col,NumRows);
    }
  }

  if (MyNodeId() > 0){
      PutLL(0, Fields);
      Send(0);
  }else{
    for(int node=1;node<NumberOfNodes();node++){
      Receive(node);
      Fields+=GetLL(node);
    }
   std::cout << Fields << "\n";
  }
}