mitkonikov

Table - Mendo

Jan 3rd, 2023
733
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.51 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #define ll long long
  3. #define endl '\n'
  4.  
  5. using namespace std;
  6.  
  7. void testCase() {
  8.     int N;
  9.     cin >> N;
  10.     vector<vector<int>> t(3, vector<int>(N));
  11.     vector<map<int, int>> frq(3);
  12.     vector<map<int, vector<int>>> occ(3);
  13.     for (int i = 0; i < 3; i++) {
  14.         for (int j = 0; j < N; j++) {
  15.             cin >> t[i][j];
  16.             frq[i][t[i][j]]++;
  17.             occ[i][t[i][j]].push_back(j);
  18.         }
  19.     }
  20.     queue<int> q;
  21.     vector<bool> deleted(N, false);
  22.     for (int i = 1; i <= N; i++) {
  23.         int MN = INT_MAX;
  24.         for (int j = 0; j < 3; j++) MN = min(MN, frq[j][i]);
  25.         if (MN == 0) q.push(i);
  26.     }
  27.     while (!q.empty()) {
  28.         int top = q.front();
  29.         q.pop();
  30.  
  31.         for (int i = 0; i < 3; i++) {
  32.             for (auto x: occ[i][top]) { // x - col
  33.                 if (deleted[x]) continue;
  34.                 for (int ii = 0; ii < 3; ii++) {
  35.                     if (i != ii) {
  36.                         auto& f = frq[ii][t[ii][x]];
  37.                         f--;
  38.                         if (f == 0) {
  39.                             q.push(t[ii][x]);
  40.                         }
  41.                     }
  42.                 }
  43.                 deleted[x] = true;
  44.             }
  45.             occ[i][top].clear();
  46.         }
  47.     }
  48.     int ans = 0;
  49.     for (int i = 0; i < N; i++) ans += (deleted[i]);
  50.     cout << ans << endl;
  51. }
  52.  
  53. int main() {
  54.     int t;
  55.     cin >> t;
  56.  
  57.     while (t--) {
  58.         testCase();
  59.     }
  60.  
  61.     cout << flush;
  62.     return 0;
  63. }
Advertisement
Add Comment
Please, Sign In to add comment