fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4. int a[55][55];
  5. int b[55][55];
  6. int main()
  7. {
  8. ios_base::sync_with_stdio(0);
  9. cout.tie(0);cin.tie(0);
  10.  
  11. int n, m; cin >> m >> n;
  12. for(int i = 1; i <= m; i++){ // duyet hang
  13. for(int j = 1; j <= n; j++){ // duyet cot
  14. cin >> a[i][j]; // phan tu hang thu i va cot thu j
  15. b[i][j] = a[i][j];
  16. }
  17. }
  18.  
  19. for(int i = 1; i <= m; i++){
  20. for(int j = 1; j <= n; j++){
  21. if(a[i][j] == 0){
  22. for(int k = 1; k <= n; k++){ // cot
  23. b[i][k] = 0;
  24. }
  25. for(int k = 1; k <= m; k++){ // hang
  26. b[k][j] = 0;
  27. }
  28. }
  29. }
  30. }
  31.  
  32. int ans = 0;
  33. for(int i = 1; i <= m; i++){ // duyet hang
  34. for(int j = 1; j <= n; j++){ // duyet cot
  35. if(b[i][j] == 1) ans++;
  36. }
  37. }
  38. cout << ans;
  39. }
  40.  
  41.  
  42.  
  43.  
  44.  
  45.  
  46.  
  47.  
  48.  
  49.  
  50.  
Success #stdin #stdout 0.01s 5288KB
stdin
Standard input is empty
stdout
Standard output is empty