Alex_tz307

1208. Legendary Teams Contest - Timus

Nov 4th, 2020
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.92 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. int main() {
  6.     ios_base::sync_with_stdio(false);
  7.     cin.tie(nullptr);
  8.     cout.tie(nullptr);
  9.     int N;
  10.     cin >> N;
  11.     vector < vector < string > > a(N, vector < string >(3));
  12.     for(int i = 0; i < N; ++i)
  13.         for(int j = 0; j < 3; ++j)
  14.             cin >> a[i][j];
  15.     int ans = 1;
  16.     for(int mask = (1 << N); mask > 0; --mask) {
  17.         unordered_map < string , bool > M;
  18.         int s = __builtin_popcount(mask);
  19.         if(s > ans) {
  20.             bool ok = true;
  21.             for(int i = 0; (1 << i) <= mask && ok; ++i)
  22.                 if(mask & (1 << i))
  23.                     for(int j = 0; j < 3 && ok; ++j)
  24.                         if(M[a[i][j]])
  25.                             ok = false;
  26.                         else
  27.                             M[a[i][j]] = true;
  28.             if(ok)
  29.                 ans = s;
  30.         }
  31.     }
  32.     cout << ans;
  33. }
  34.  
Advertisement
Add Comment
Please, Sign In to add comment