#include "dzialka.h" #include "message.h" #include <stdint.h> #include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); if(MyNodeId() != 0) return 0; int const r = GetFieldHeight(); int const c = GetFieldWidth(); vector< vector<bool> > d(r, vector<bool>(c)); uint64_t ans = 0; for(int i = 0; i < r; i++) { for(int j = 0; j < c; j++) { d[i][j] = IsUsableCell(i, j); } } for(int t = 1; t <= c; t++) { int tc = c - t + 1; if(t != 1) { for(int i = 0; i < r; i++) { for(int j = tc; j--> 0;) { if(not d[i][j+1]) d[i][j] = false; } } } for(int j = 0; j < tc; j++) { int n = 0; for(int i = 0; i < r; i++) { if(d[i][j]) { n++; } else { ans += n * int64_t(n + 1) / 2; n = 0; } } ans += n * int64_t(n + 1) / 2; } } cout << ans << '\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 | #include "dzialka.h" #include "message.h" #include <stdint.h> #include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); if(MyNodeId() != 0) return 0; int const r = GetFieldHeight(); int const c = GetFieldWidth(); vector< vector<bool> > d(r, vector<bool>(c)); uint64_t ans = 0; for(int i = 0; i < r; i++) { for(int j = 0; j < c; j++) { d[i][j] = IsUsableCell(i, j); } } for(int t = 1; t <= c; t++) { int tc = c - t + 1; if(t != 1) { for(int i = 0; i < r; i++) { for(int j = tc; j--> 0;) { if(not d[i][j+1]) d[i][j] = false; } } } for(int j = 0; j < tc; j++) { int n = 0; for(int i = 0; i < r; i++) { if(d[i][j]) { n++; } else { ans += n * int64_t(n + 1) / 2; n = 0; } } ans += n * int64_t(n + 1) / 2; } } cout << ans << '\n'; return 0; } |