#include "dzialka.h"
#include "message.h"
#include <iostream>
long long solve(int lead_id) {
const long long node_id = (long long)MyNodeId();
const long long nodes_num = (long long)NumberOfNodes();
const int NumRows = GetFieldHeight();
const int NumCols = GetFieldWidth();
long long rectangles_num = 0;
long long vertex = node_id;
int start_row = (int) (vertex / (long long) NumCols);
int start_col = (int) (vertex % (long long) NumCols);
while (start_row < NumRows) {
int max_row = NumRows;
int max_col = NumCols;
int row = start_row;
while (row < max_row) {
int col = start_col;
while (col < max_col) {
if (IsUsableCell(row, col)) {
rectangles_num++;
} else {
max_col = col;
}
col++;
}
if (max_col == 0) {
max_row = row;
}
row++;
}
vertex += nodes_num;
start_row = (int) (vertex / NumCols);
start_col = (int) (vertex % NumCols);
}
if (lead_id != node_id) {
PutLL(lead_id, rectangles_num);
Send(lead_id);
}
return rectangles_num;
}
int main() {
const int node_id = MyNodeId();
const int nodes_num = NumberOfNodes();
const int lead_id = nodes_num - 1;
long long Result = solve(lead_id);
if (node_id != lead_id) {
return 0;
}
int sender_id;
long long partial;
for (int i = 0; i < nodes_num - 1; i++) {
sender_id = Receive(-1);
partial = GetLL(sender_id);
Result += partial;
}
std::cout << Result << "\n";
return 0;
}
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 74 75 | #include "dzialka.h" #include "message.h" #include <iostream> long long solve(int lead_id) { const long long node_id = (long long)MyNodeId(); const long long nodes_num = (long long)NumberOfNodes(); const int NumRows = GetFieldHeight(); const int NumCols = GetFieldWidth(); long long rectangles_num = 0; long long vertex = node_id; int start_row = (int) (vertex / (long long) NumCols); int start_col = (int) (vertex % (long long) NumCols); while (start_row < NumRows) { int max_row = NumRows; int max_col = NumCols; int row = start_row; while (row < max_row) { int col = start_col; while (col < max_col) { if (IsUsableCell(row, col)) { rectangles_num++; } else { max_col = col; } col++; } if (max_col == 0) { max_row = row; } row++; } vertex += nodes_num; start_row = (int) (vertex / NumCols); start_col = (int) (vertex % NumCols); } if (lead_id != node_id) { PutLL(lead_id, rectangles_num); Send(lead_id); } return rectangles_num; } int main() { const int node_id = MyNodeId(); const int nodes_num = NumberOfNodes(); const int lead_id = nodes_num - 1; long long Result = solve(lead_id); if (node_id != lead_id) { return 0; } int sender_id; long long partial; for (int i = 0; i < nodes_num - 1; i++) { sender_id = Receive(-1); partial = GetLL(sender_id); Result += partial; } std::cout << Result << "\n"; return 0; } |
English