fork download
  1. #include"bits/stdc++.h"
  2. #define int long long
  3. using namespace std;
  4.  
  5. void TEST_CASE() {
  6. int n;
  7. cin >> n;
  8. vector<string>s(n);
  9. for (int i = 0; i < n; i++) {
  10. cin >> s[i];
  11. }
  12. vector<bitset<2005>>bit(n), bit2(n);
  13. for (int i = 0; i < n; i++) {
  14. for (int j = 0; j < n; j++) {
  15. if (s[i][j] == '1') {
  16. bit[i][j] = 1;
  17. bit2[i][j] = 1;
  18. }
  19. }
  20. }
  21. int ans = 0;
  22. for (int i = 0; i < n; i++) {
  23. for (int j = i + 1; j < n; j++) {
  24. bit[i] &= bit[j];
  25. int cnt = bit[i].count();
  26. ans += (cnt * (cnt - 1)) / 2;
  27. bit[i] |= bit2[i];
  28. }
  29. }
  30. cout << ans << endl;
  31. }
  32.  
  33. signed main() {
  34. ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  35. int t = 1;
  36. //cin >> t;
  37. while (t--) {
  38. TEST_CASE();
  39. }
  40. return 0;
  41. }
  42.  
Success #stdin #stdout 0.03s 5456KB
stdin
Standard input is empty
stdout
0