fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main() {
  5. cin.tie(0);
  6. ios::sync_with_stdio(false);
  7.  
  8. int n, res = 0;
  9. cin >> n;
  10.  
  11. vector <vector <int>> g(n + 1, vector<int>(n));
  12.  
  13. for (int i = 0; i < n; i++) {
  14. for (int j = 0; j < n; j++) {
  15. cin >> g[i][j];
  16. }
  17. }
  18.  
  19. for (int i = 0; i < n; i++) {
  20. cin >> g[n][i];
  21. }
  22.  
  23. for (int i = 0; i < n ; i++) {
  24. for (int j = i; j < n; j++) {
  25. if (
  26. g[i][j] == 1 &&
  27. g[n][i] != g[n][j]
  28. ) {
  29. res++;
  30. }
  31. }
  32. }
  33.  
  34. cout << res;
  35. return 0;
  36. }
Success #stdin #stdout 0s 5320KB
stdin
7
0 1 0 0 0 1 1
1 0 1 0 0 0 0
0 1 0 0 1 1 0
0 0 0 0 0 0 0
0 0 1 0 0 1 0
1 0 1 0 1 0 0
1 0 0 0 0 0 0

1 1 1 1 1 3 3
stdout
4