#include <iostream> #include "dzialka.h" #include "message.h" using namespace std; const int N = 3002; int field[N][N]; long long sum[N][N]; int height, width; int main() { ios_base::sync_with_stdio(0); if (MyNodeId() == 0) { height = GetFieldHeight(); width = GetFieldWidth(); for (int i = 0; i < width; i++) { for (int j = 0; j < height; j++) { field[i][j] = IsUsableCell(j, i); } } for (int i = width - 1; i >= 0; i--) { for (int j = height - 1; j >= 0; j--) { if (field[i][j]) { sum[i][j] = sum[i + 1][j] + sum[i][j + 1] + 1; if (sum[i + 1][j] != 0 || sum[i][j + 1] != 0) { sum[i][j] -= sum[i + 1][j + 1]; } } } } for (int i = width - 1; i >= 0; i--) { for (int j = height - 1; j >= 0; j--) { if (field[i][j]) { sum[i][j] += sum[i + 1][j] + sum[i][j + 1] - sum[i + 1][j + 1]; } else { sum[i][j] = sum[i + 1][j] + sum[i][j + 1] - sum[i + 1][j + 1]; } } } cout << sum[0][0]; } 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 | #include <iostream> #include "dzialka.h" #include "message.h" using namespace std; const int N = 3002; int field[N][N]; long long sum[N][N]; int height, width; int main() { ios_base::sync_with_stdio(0); if (MyNodeId() == 0) { height = GetFieldHeight(); width = GetFieldWidth(); for (int i = 0; i < width; i++) { for (int j = 0; j < height; j++) { field[i][j] = IsUsableCell(j, i); } } for (int i = width - 1; i >= 0; i--) { for (int j = height - 1; j >= 0; j--) { if (field[i][j]) { sum[i][j] = sum[i + 1][j] + sum[i][j + 1] + 1; if (sum[i + 1][j] != 0 || sum[i][j + 1] != 0) { sum[i][j] -= sum[i + 1][j + 1]; } } } } for (int i = width - 1; i >= 0; i--) { for (int j = height - 1; j >= 0; j--) { if (field[i][j]) { sum[i][j] += sum[i + 1][j] + sum[i][j + 1] - sum[i + 1][j + 1]; } else { sum[i][j] = sum[i + 1][j] + sum[i][j + 1] - sum[i + 1][j + 1]; } } } cout << sum[0][0]; } return 0; } |