#include "dzialka.h" #include "message.h" #include <iostream> #include <stack> #include <cstring> #include <algorithm> using namespace std; #define MAXN 80000 int num_rows; int num_cols; long long int w[MAXN]; long long int r[MAXN]; long long solve(int min_col, int max_col) { long long int result = 0; for(int j = min_col; j <= max_col; j++) { stack<int> q; q.push(0); for(int i = 1; i <= num_rows; i++) { if(IsUsableCell(i - 1, j - 1)) { w[i] = w[i] + 1; } else { w[i] = 0; } while(true) { if (w[q.top()] > w[i]) { q.pop(); } else { break; } } r[i] = r[q.top()] + (i - q.top()) * w[i]; q.push(i); result += r[i]; } } return result; } int main() { num_rows = GetFieldHeight(); num_cols = GetFieldWidth(); memset(r, 0, MAXN * sizeof(long long int)); memset(w, 0, MAXN * sizeof(long long int)); long long int result = 0; if (MyNodeId() == 0) { result = solve(1, num_cols / 2); PutLL(1, result); for(int i = 1; i <= num_rows; i++) { PutLL(1, w[i]); PutLL(1, r[i]); } Send(1); } else if(MyNodeId() == 1) { Receive(0); result = GetLL(0); for(int i = 1; i <= num_rows; i++) { w[i] = GetLL(0); r[i] = GetLL(0); } result += solve(num_cols / 2 + 1, num_cols); printf("%lld\n", result); } else { return 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 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 | #include "dzialka.h" #include "message.h" #include <iostream> #include <stack> #include <cstring> #include <algorithm> using namespace std; #define MAXN 80000 int num_rows; int num_cols; long long int w[MAXN]; long long int r[MAXN]; long long solve(int min_col, int max_col) { long long int result = 0; for(int j = min_col; j <= max_col; j++) { stack<int> q; q.push(0); for(int i = 1; i <= num_rows; i++) { if(IsUsableCell(i - 1, j - 1)) { w[i] = w[i] + 1; } else { w[i] = 0; } while(true) { if (w[q.top()] > w[i]) { q.pop(); } else { break; } } r[i] = r[q.top()] + (i - q.top()) * w[i]; q.push(i); result += r[i]; } } return result; } int main() { num_rows = GetFieldHeight(); num_cols = GetFieldWidth(); memset(r, 0, MAXN * sizeof(long long int)); memset(w, 0, MAXN * sizeof(long long int)); long long int result = 0; if (MyNodeId() == 0) { result = solve(1, num_cols / 2); PutLL(1, result); for(int i = 1; i <= num_rows; i++) { PutLL(1, w[i]); PutLL(1, r[i]); } Send(1); } else if(MyNodeId() == 1) { Receive(0); result = GetLL(0); for(int i = 1; i <= num_rows; i++) { w[i] = GetLL(0); r[i] = GetLL(0); } result += solve(num_cols / 2 + 1, num_cols); printf("%lld\n", result); } else { return 0; } return 0; } |