Advertisement
zhukov000

Area planing

Feb 26th, 2020
234
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.86 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #define F first
  3. #define S second
  4.  
  5. using namespace std;
  6.  
  7. int a[401][401] = {};
  8.  
  9. int main()
  10. {
  11.   ios_base::sync_with_stdio(0);
  12.   #ifdef AZHUKOV
  13.   freopen("input.txt", "r", stdin);
  14.   #endif // AZHUKOV
  15.   int n;
  16.   cin >> n;
  17.   vector<pair<int, int> > q;
  18.   for(int i=0; i<n; ++i)
  19.   {
  20.     for(int j=0; j<n; ++j)
  21.     {
  22.       q.push_back( {i, j} );
  23.       cin >> a[i][j];
  24.     }
  25.   }
  26.  
  27.   sort(q.begin(), q.end(), [](pair<int, int> x, pair<int, int> y) {
  28.     return a[x.F][x.S] > a[y.F][y.S] || (a[x.F][x.S] == a[y.F][y.S] && x.F < y.F);
  29.   });
  30.  
  31.   vector<int> ans(n);
  32.   vector<bool> company(n, false);
  33.   vector<bool> area(n, false);
  34.  
  35.   for(auto p: q)
  36.   {
  37.     if (!company[p.F] && !area[p.S])
  38.     {
  39.       company[p.F] = area[p.S] = true;
  40.       ans[p.F] = p.S;
  41.     }
  42.   }
  43.  
  44.   for(auto x: ans)
  45.     cout << x + 1 << " ";
  46.   return 0;
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement