fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define int long long int
  4. #define double long double
  5. #define print(a) for(auto x : a) cout << x << " "; cout << endl
  6.  
  7. const int M = 1000000007;;
  8. const int N = 3e5+9;
  9. const int INF = 2e9+1;
  10. const int LINF = 2000000000000000001;
  11.  
  12. inline int power(int a, int b, int mod=M) {
  13. int x = 1;
  14. a %= mod;
  15. while (b) {
  16. if (b & 1) x = (x * a) % mod;
  17. a = (a * a) % mod;
  18. b >>= 1;
  19. }
  20. return x;
  21. }
  22.  
  23.  
  24.  
  25. //_ ***************************** START Below *******************************
  26.  
  27.  
  28.  
  29. int nCr(int n, int r){
  30. if(r<0 || r>n) return 0;
  31. if(r > n-r) r = n-r;
  32.  
  33. int res = 1;
  34. for(int k=1; k<=r; k++){
  35. res *= (n-k+1);
  36. res /= k;
  37. }
  38.  
  39. return res;
  40.  
  41. }
  42.  
  43. vector<vector<int>> a;
  44.  
  45. int consistency(int m, int n){
  46.  
  47. int ans = m*n; //* All single element sequences
  48.  
  49. //* row wise 2 sized, 3 sized ,,, sequences of 0 & 1 colors
  50. for(int i=0; i<m; i++){
  51. int ones = 0;
  52. int zeroes = 0;
  53. for(int j=0; j<n; j++){
  54. if(a[i][j] == 0) zeroes++;
  55. else ones++;
  56. }
  57. for(int k=2; k<=zeroes; k++){
  58. ans += nCr(zeroes, k);
  59. }
  60. for(int k=2; k<=ones; k++){
  61. ans += nCr(ones, k);
  62. }
  63. }
  64.  
  65. //* col wise 2 sized, 3 sized ,,, sequences of 0 & 1 colors
  66. for(int j=0; j<n; j++){
  67. int ones = 0;
  68. int zeroes = 0;
  69. for(int i=0; i<m; i++){
  70. if(a[i][j] == 0) zeroes++;
  71. else ones++;
  72. }
  73. for(int k=2; k<=zeroes; k++){
  74. ans += nCr(zeroes, k);
  75. }
  76. for(int k=2; k<=ones; k++){
  77. ans += nCr(ones, k);
  78. }
  79. }
  80.  
  81. return ans;
  82. }
  83.  
  84.  
  85.  
  86.  
  87.  
  88.  
  89.  
  90.  
  91.  
  92.  
  93.  
  94.  
  95.  
  96.  
  97.  
  98. int practice(int m, int n){
  99.  
  100.  
  101. return 0;
  102. }
  103.  
  104.  
  105.  
  106.  
  107.  
  108. void solve() {
  109.  
  110. int m, n;
  111. cin >> m >> n;
  112. a.resize(m, vector<int>(n, 0));
  113. for(int i=0; i<m; i++){
  114. for(int j=0; j<n; j++) cin >> a[i][j];
  115. }
  116.  
  117. cout << consistency(m, n) << endl;
  118.  
  119.  
  120. }
  121.  
  122.  
  123.  
  124.  
  125.  
  126. int32_t main() {
  127. ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  128.  
  129. int t = 1;
  130. // cin >> t;
  131. while (t--) {
  132. solve();
  133. }
  134.  
  135. return 0;
  136. }
Success #stdin #stdout 0s 5308KB
stdin
2 2
1 1
1 1
stdout
8