1
0

AtCoder-abc258_g.cpp 684 B

12345678910111213141516171819202122232425
  1. #include <bitset>
  2. #include <iostream>
  3. #include <string>
  4. #include <vector>
  5. using namespace std;
  6. int main() {
  7. ios::sync_with_stdio(false);
  8. cin.tie(nullptr);
  9. int n; cin >> n;
  10. constexpr int max_n = 3000;
  11. vector<bitset<max_n>> neighbor(n);
  12. vector<string> matrix(n);
  13. for (int i = 0; i < n; ++i) {
  14. cin >> matrix[i];
  15. for (int j = 0; j < n; ++j) if (matrix[i][j] == '1') neighbor[i].set(j);
  16. }
  17. long long sum = 0;
  18. for (int i = 0; i < n; ++i) {
  19. for (int j = i + 1; j < n; ++j) if (matrix[i][j] == '1') {
  20. sum += static_cast<long long>((neighbor[i] & neighbor[j]).count());
  21. }
  22. }
  23. cout << sum / 3 << '\n';
  24. }