Advertisement
Alex_tz307

IOIT airstrike - 15p

Dec 15th, 2020
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.33 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #define x first
  3. #define y second
  4.  
  5. using namespace std;
  6.  
  7. int main() {
  8.     ios_base::sync_with_stdio(false);
  9.     cin.tie(nullptr);
  10.     cout.tie(nullptr);
  11.     int N;
  12.     cin >> N;
  13.     vector<pair<int,int>> a(N);
  14.     for(auto &x : a)
  15.         cin >> x.x >> x.y;
  16.     vector<bool> mark(N);
  17.     int ans = 0, erased = 0;
  18.     while(erased < N) {
  19.         ++ans;
  20.         vector<int> cntX(N + 1), cntY(N + 1);
  21.         int mx = 0, type = 1, v = 0;
  22.         for(int i = 0; i < N; ++i)
  23.             if(!mark[i]) {
  24.                 ++cntX[a[i].x], ++cntY[a[i].y];
  25.                 if(cntX[a[i].x] > mx) {
  26.                     mx = cntX[a[i].x];
  27.                     type = 1;
  28.                     v = a[i].x;
  29.                 }
  30.                 if(cntY[a[i].y] > mx) {
  31.                     mx = cntY[a[i].y];
  32.                     type = 0;
  33.                     v = a[i].y;
  34.                 }
  35.             }
  36.         if(type == 1) {
  37.             for(int i = 0; i < N; ++i)
  38.                 if(!mark[i] && a[i].x == v) {
  39.                     mark[i] = true;
  40.                     ++erased;
  41.                 }
  42.         }
  43.         else
  44.             for(int i = 0; i < N; ++i)
  45.                 if(!mark[i] && a[i].y == v) {
  46.                     mark[i] = true;
  47.                     ++erased;
  48.                 }
  49.     }
  50.     cout << ans;
  51. }
  52.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement