Advertisement
Guest User

Untitled

a guest
Sep 19th, 2021
769
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.16 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. using ll = long long;
  6.  
  7. const int N = 2000;
  8.  
  9. bitset<N> b[N], y[N];
  10.  
  11. void solve() {
  12.     int n;
  13.     cin >> n;
  14.     vector<string> g(n);
  15.     for (int i = 0; i < n; i++) {
  16.         cin >> g[i];
  17.         for (int j = 0; j < n; j++) {
  18.             if (i == j) continue;
  19.             if (g[i][j] == 'B') {
  20.                 b[i].set(j);
  21.             } else {
  22.                 y[i].set(j);
  23.             }
  24.         }
  25.     }
  26.  
  27.     vector<ll> cnt(2);
  28.     for (int i = 0; i < n; i++) {
  29.         for (int j = i + 1; j < n; j++) {
  30.             int kek = 0;
  31.             if (g[i][j] == 'B') {
  32.                 kek = (y[i] & y[j]).count();
  33.             } else {
  34.                 kek = (b[i] & b[j]).count();
  35.             }
  36.             cnt[0] += kek * (kek - 1) / 2;
  37.             cnt[1] += (y[i] & b[j]).count() * (b[i] & y[j]).count();
  38.         }
  39.     }
  40.     cout << cnt[1] /  2 - cnt[0] << endl;
  41. }
  42.  
  43. int main() {
  44.     ios::sync_with_stdio(false);
  45.     cin.tie(nullptr);
  46.     int T = 1;
  47.     // cin >> T;
  48.     for (int tc = 1; tc <= T; tc++) {
  49.         // cout << "Case #" << tc << ": ";  
  50.         solve();
  51.     }
  52.     return 0;
  53. }
  54.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement