#include <iostream> #include <vector> #include "dzialka.h" #include "message.h" using namespace std; int main() { if (MyNodeId() != 0) return EXIT_SUCCESS; int n = GetFieldHeight(); int m = GetFieldWidth(); vector< vector<int> > s(n, vector<int>(m)); for (int i = 0; i < n; ++i) { for (int j = 0; j < m; ++j) { s[i][j] = IsUsableCell(i, j); s[i][j] ^= 1; } } for (int i = 0; i < n; ++i) { for (int j = 0; j < m; ++j) { if (i - 1 >= 0) s[i][j] += s[i - 1][j]; if (j - 1 >= 0) s[i][j] += s[i][j - 1]; if (i - 1 >= 0 && j - 1 >= 0) s[i][j] -= s[i - 1][j - 1]; } } int odp = 0; for (int i = 0; i < n; ++i) { for (int j = 0; j < m; ++j) { for (int k = i; k < n; ++k) { for (int l = j; l < m; ++l) { int suma = s[k][l]; if (i - 1 >= 0) suma -= s[i - 1][l]; if (j - 1 >= 0) suma -= s[k][j - 1]; if (i - 1 >= 0 && j - 1 >= 0) suma += s[i - 1][j - 1]; if (suma == 0) ++odp; } } } } cout << odp; return EXIT_SUCCESS; }
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 | #include <iostream> #include <vector> #include "dzialka.h" #include "message.h" using namespace std; int main() { if (MyNodeId() != 0) return EXIT_SUCCESS; int n = GetFieldHeight(); int m = GetFieldWidth(); vector< vector<int> > s(n, vector<int>(m)); for (int i = 0; i < n; ++i) { for (int j = 0; j < m; ++j) { s[i][j] = IsUsableCell(i, j); s[i][j] ^= 1; } } for (int i = 0; i < n; ++i) { for (int j = 0; j < m; ++j) { if (i - 1 >= 0) s[i][j] += s[i - 1][j]; if (j - 1 >= 0) s[i][j] += s[i][j - 1]; if (i - 1 >= 0 && j - 1 >= 0) s[i][j] -= s[i - 1][j - 1]; } } int odp = 0; for (int i = 0; i < n; ++i) { for (int j = 0; j < m; ++j) { for (int k = i; k < n; ++k) { for (int l = j; l < m; ++l) { int suma = s[k][l]; if (i - 1 >= 0) suma -= s[i - 1][l]; if (j - 1 >= 0) suma -= s[k][j - 1]; if (i - 1 >= 0 && j - 1 >= 0) suma += s[i - 1][j - 1]; if (suma == 0) ++odp; } } } } cout << odp; return EXIT_SUCCESS; } |