#include "dzialka.h"
#include "message.h"
#include<cstdio>
int main(){
int n = GetFieldHeight();
int m = GetFieldWidth();
long long int wynik = 0;
int t[m];
int stosG[m];
int stosI[m];
for(int i = 0; i < m; ++i){
t[i]=0;
}
if(MyNodeId()==0){
for(int i=0; i < n; ++i){
for(int j=0; j < n; ++j){
int x = IsUsableCell(i, j);
if(x==0){
t[j]=0;
}else{
t[j]+=x;
}
}
int tmp=0;
for(int j=0; j < n; ++j){
while(tmp > 0 && stosG[tmp] > t[j]){
tmp--;
}
int popG=0;
for(int i=1; i <=tmp; ++i){
if((i+1) < tmp){
int prze=stosI[i+1]-stosI[i];
wynik+=prze*((stosG[i]*(stosG[i]+1))/2);
}else{
int prze=j-stosI[i];
wynik+=prze*((stosG[i]*(stosG[i]+1))/2);
}
wynik+=(j*(j+1))/2;
}
if(tmp > 0 && stosG[tmp] == t[j]){
stosG[tmp]=t[j];
stosI[tmp]=j;
}else{
tmp++;
stosG[tmp]=t[j];
stosI[tmp]=j;
}
}
}
printf("%lld\n", wynik);
}
}
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 | #include "dzialka.h" #include "message.h" #include<cstdio> int main(){ int n = GetFieldHeight(); int m = GetFieldWidth(); long long int wynik = 0; int t[m]; int stosG[m]; int stosI[m]; for(int i = 0; i < m; ++i){ t[i]=0; } if(MyNodeId()==0){ for(int i=0; i < n; ++i){ for(int j=0; j < n; ++j){ int x = IsUsableCell(i, j); if(x==0){ t[j]=0; }else{ t[j]+=x; } } int tmp=0; for(int j=0; j < n; ++j){ while(tmp > 0 && stosG[tmp] > t[j]){ tmp--; } int popG=0; for(int i=1; i <=tmp; ++i){ if((i+1) < tmp){ int prze=stosI[i+1]-stosI[i]; wynik+=prze*((stosG[i]*(stosG[i]+1))/2); }else{ int prze=j-stosI[i]; wynik+=prze*((stosG[i]*(stosG[i]+1))/2); } wynik+=(j*(j+1))/2; } if(tmp > 0 && stosG[tmp] == t[j]){ stosG[tmp]=t[j]; stosI[tmp]=j; }else{ tmp++; stosG[tmp]=t[j]; stosI[tmp]=j; } } } printf("%lld\n", wynik); } } |
English