Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define F first
- #define S second
- using namespace std;
- int a[401][401] = {};
- int main()
- {
- ios_base::sync_with_stdio(0);
- #ifdef AZHUKOV
- freopen("input.txt", "r", stdin);
- #endif // AZHUKOV
- int n;
- cin >> n;
- vector<pair<int, int> > q;
- for(int i=0; i<n; ++i)
- {
- for(int j=0; j<n; ++j)
- {
- q.push_back( {i, j} );
- cin >> a[i][j];
- }
- }
- sort(q.begin(), q.end(), [](pair<int, int> x, pair<int, int> y) {
- 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);
- });
- vector<int> ans(n);
- vector<bool> company(n, false);
- vector<bool> area(n, false);
- for(auto p: q)
- {
- if (!company[p.F] && !area[p.S])
- {
- company[p.F] = area[p.S] = true;
- ans[p.F] = p.S;
- }
- }
- for(auto x: ans)
- cout << x + 1 << " ";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement