#include <bits/stdc++.h> #include "message.h" #include "dzialka.h" using namespace std; #define int long long int NR = NumberOfNodes(); int ID = MyNodeId(); int w = GetFieldWidth(); int h = GetFieldHeight(); int tab[2][75010]; int foo( int szerokosc, int wysokosc ) { return wysokosc*szerokosc*(szerokosc+1)/2; } vector<pair<int, int> > v[1010]; int32_t main() { int l = (w-1)/990+1; int addH = ((h-1)/NR+1)*ID; //cout << l << " " << addH << endl; //l = 10000000; //cout << w << " " << h << endl; //if( ID != 0 ) return 0; int res = 0; //cout << w << " " << h << " " << l << " " << addH << endl; for( int i=0; i<1010; i++ ) { v[i].push_back( {0, 0} ); } for( int pocz=1; pocz<=w; pocz+=l ) { if( ID!=0 ) { Receive( ID-1 ); for( int i=pocz; i<min( pocz+l, w+1 ); i++ ) { tab[0][i] = GetLL( ID-1 ); } } int gdzie_r=0; for( int r=1; r+addH<=h&&r<=((h-1)/NR+1); r++ ) { for( int c=pocz; c<min( pocz+l, w+1 ); c++ ) { tab[r%2][c] = tab[(r-1)%2][c]+1; if( !IsUsableCell( addH+r-1, c-1 ) ) tab[r%2][c] = 0; while( tab[r%2][c] < v[r].back().first ) { res += foo( c-v[r].back().second, v[r].back().first-v[r][(int)v[r].size()-2].first ); v[r].pop_back(); } //if( ID == 0 ) //cout << r << " " << c << " " << res << "\n" ; if( tab[r%2][c] > v[r].back().first ) v[r].push_back( {tab[r%2][c], c} ); } gdzie_r = r; } if( ID+1 == NR ) continue; for( int c=pocz; c<min( pocz+l, w+1 ); c++ ) { PutLL( ID+1, tab[gdzie_r%2][c] ); } Send( ID+1 ); } for( int r=0; r<1010; r++ ) { while( v[r].size() > 1 ) { res += foo( w+1-v[r].back().second, v[r].back().first-v[r][(int)v[r].size()-2].first ); v[r].pop_back(); } } //cout << res; PutLL( 0, res ); Send( 0 ); if( ID != 0 ) return 0; res = 0; for( int i=0; i<NR; i++ ) { Receive( i ); res += GetLL( i ); } cout << res; 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 80 81 82 83 | #include <bits/stdc++.h> #include "message.h" #include "dzialka.h" using namespace std; #define int long long int NR = NumberOfNodes(); int ID = MyNodeId(); int w = GetFieldWidth(); int h = GetFieldHeight(); int tab[2][75010]; int foo( int szerokosc, int wysokosc ) { return wysokosc*szerokosc*(szerokosc+1)/2; } vector<pair<int, int> > v[1010]; int32_t main() { int l = (w-1)/990+1; int addH = ((h-1)/NR+1)*ID; //cout << l << " " << addH << endl; //l = 10000000; //cout << w << " " << h << endl; //if( ID != 0 ) return 0; int res = 0; //cout << w << " " << h << " " << l << " " << addH << endl; for( int i=0; i<1010; i++ ) { v[i].push_back( {0, 0} ); } for( int pocz=1; pocz<=w; pocz+=l ) { if( ID!=0 ) { Receive( ID-1 ); for( int i=pocz; i<min( pocz+l, w+1 ); i++ ) { tab[0][i] = GetLL( ID-1 ); } } int gdzie_r=0; for( int r=1; r+addH<=h&&r<=((h-1)/NR+1); r++ ) { for( int c=pocz; c<min( pocz+l, w+1 ); c++ ) { tab[r%2][c] = tab[(r-1)%2][c]+1; if( !IsUsableCell( addH+r-1, c-1 ) ) tab[r%2][c] = 0; while( tab[r%2][c] < v[r].back().first ) { res += foo( c-v[r].back().second, v[r].back().first-v[r][(int)v[r].size()-2].first ); v[r].pop_back(); } //if( ID == 0 ) //cout << r << " " << c << " " << res << "\n" ; if( tab[r%2][c] > v[r].back().first ) v[r].push_back( {tab[r%2][c], c} ); } gdzie_r = r; } if( ID+1 == NR ) continue; for( int c=pocz; c<min( pocz+l, w+1 ); c++ ) { PutLL( ID+1, tab[gdzie_r%2][c] ); } Send( ID+1 ); } for( int r=0; r<1010; r++ ) { while( v[r].size() > 1 ) { res += foo( w+1-v[r].back().second, v[r].back().first-v[r][(int)v[r].size()-2].first ); v[r].pop_back(); } } //cout << res; PutLL( 0, res ); Send( 0 ); if( ID != 0 ) return 0; res = 0; for( int i=0; i<NR; i++ ) { Receive( i ); res += GetLL( i ); } cout << res; return 0; } |