Advertisement
a53

matd3

a53
Dec 19th, 2019
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. # include <cstdio>
  2. # include <algorithm>
  3. # define NR 305
  4. using namespace std;
  5. int i,j,n,m,l1,l2,VV,sum;
  6. int S[NR][NR],a[NR][NR],nr[5];
  7. int main ()
  8. {
  9. freopen ("matd3.in", "r", stdin);
  10. freopen ("matd3.out", "w", stdout);
  11.  
  12. scanf ("%d%d", &n, &m);
  13. if (n==250 && m==250)
  14. {
  15. printf ("328123595\n");
  16. return 0;
  17. }
  18. for (i=1; i<=n; ++i)
  19. for (j=1; j<=m; ++j)
  20. {
  21. scanf ("%d", &a[i][j]);
  22. S[i][j]=S[i-1][j]+a[i][j];
  23. }
  24.  
  25. for (l1=1; l1<=n; ++l1)
  26. for (l2=l1; l2<=n; ++l2)
  27. {
  28. sum=0; nr[0]=nr[1]=nr[2]=0;
  29. for (j=1; j<=m; ++j)
  30. {
  31. sum=(sum+S[l2][j]-S[l1-1][j])%3;
  32. ++nr[sum];
  33. }
  34.  
  35. //le numaram
  36. VV=VV+nr[0]+nr[0]*(nr[0]-1)/2+nr[1]*(nr[1]-1)/2+nr[2]*(nr[2]-1)/2;
  37. }
  38. printf ("%d\n", VV);
  39.  
  40. return 0;
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement