Advertisement
a53

paralele1

a53
Mar 14th, 2019
224
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.33 KB | None | 0 0
  1. //Raluca Costineanu
  2. #include <bits/stdc++.h>
  3.  
  4. using namespace std;
  5. #define nMax 50010
  6. #define mMax 1010
  7.  
  8. ifstream f("paralele.in");
  9. ofstream g("paralele.out");
  10.  
  11. int n, m, t;
  12. long long lin[nMax], col[mMax], lgCol[nMax];
  13. bool a[mMax];
  14. long long peLinii()
  15. {
  16. int i, j, lg;
  17. long long total=0;
  18. for(i=1;i<=n;i++)
  19. {
  20. for(j=1;j<=m;j++)
  21. f>>a[j];
  22. lg=0;
  23. for(j=1;j<=m+1;j++)
  24. if(a[j]==1)
  25. lg++;
  26. else lin[i]+=1LL*lg*(lg-1)/2, lg=0;
  27. total+=lin[i];
  28. }
  29. total=total*(total-1)/2;
  30. for(i=1;i<=n;i++)
  31. total-=1LL*lin[i]*(lin[i]-1)/2;
  32. return total;
  33. }
  34. long long peColoane()
  35. {
  36. long long total=0;
  37. int i, j;
  38. for(i=1;i<=n;i++)
  39. {
  40. for(j=1;j<=m;j++)
  41. f>>a[j];
  42. for(j=1;j<=m+1;j++)
  43. if(a[j]==1)
  44. lgCol[j]++;
  45. else col[j]+=1LL*lgCol[j]*(lgCol[j]-1)/2, lgCol[j]=0;
  46. }
  47. for(j=1;j<=m;j++)
  48. {
  49. if(lgCol[j])
  50. col[j]+=1LL*lgCol[j]*(lgCol[j]-1)/2;
  51. total+=col[j];
  52. }
  53. total=total*(total-1)/2;
  54. for(j=1;j<=m;j++)
  55. total-=1LL*col[j]*(col[j]-1)/2;
  56. return total;
  57. }
  58. int main()
  59. {
  60. f>>t>>n>>m;
  61. if(t==1)
  62. g<<peLinii()<<'\n';
  63. else
  64. g<<peColoane()<<'\n';
  65. return 0;
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement