#include "dzialka.h" #include "message.h" #include <iostream> int main() { if (MyNodeId() > 0) return 0; const int N = GetFieldHeight(); const int M = GetFieldWidth(); long long cnt = 0; int tab[N][M]; for(int i = 0; i < M; ++i) { if(IsUsableCell(0, i)) { tab[0][i] = 1; } else { tab[0][i] = 0; } } for(int i = 1; i < N; ++i) { for(int j = 0; j < M; ++j) { if(IsUsableCell(i, j)) { tab[i][j] = 1 + tab[i - 1][j]; } else { tab[i][j] = 0; } } } for(int i = 0; i < N; ++i) { for(int j = 0 ; j < M; ++j) { int mina = tab[i][j]; if(tab[i][j]) { cnt += mina; for(int l = j+1; l < M; ++l) { if(!tab[i][l])break; else { mina = std:: min(tab[i][l], mina); cnt += mina; } } } } } std::cout << cnt; }
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 | #include "dzialka.h" #include "message.h" #include <iostream> int main() { if (MyNodeId() > 0) return 0; const int N = GetFieldHeight(); const int M = GetFieldWidth(); long long cnt = 0; int tab[N][M]; for(int i = 0; i < M; ++i) { if(IsUsableCell(0, i)) { tab[0][i] = 1; } else { tab[0][i] = 0; } } for(int i = 1; i < N; ++i) { for(int j = 0; j < M; ++j) { if(IsUsableCell(i, j)) { tab[i][j] = 1 + tab[i - 1][j]; } else { tab[i][j] = 0; } } } for(int i = 0; i < N; ++i) { for(int j = 0 ; j < M; ++j) { int mina = tab[i][j]; if(tab[i][j]) { cnt += mina; for(int l = j+1; l < M; ++l) { if(!tab[i][l])break; else { mina = std:: min(tab[i][l], mina); cnt += mina; } } } } } std::cout << cnt; } |