제출 #301039

#제출 시각아이디문제언어결과실행 시간메모리
301039Khongor카니발 티켓 (IOI20_tickets)C++14
11 / 100
3 ms768 KiB
#include "tickets.h" #include <bits/stdc++.h> using namespace std; vector<vector<int>> ans; long long find_maximum(int k, std::vector<std::vector<int>> x) { int n = x.size(); int m = x[0].size(); ans = vector<vector<int>>(n, vector<int>(m, -1)); long long res = 0; for (int r = 0; r < k; r++) { multiset<pair<int, int>> s; vector<pair<int, int>> a(n); for (int i = 0; i < n; i++) { int mn = -1; int mx = -1; for (int j = 0; j < m; j++) if (ans[i][j] == -1) { if (mn == -1 || x[i][j] < x[i][mn]) mn = j; if (mx == -1 || x[i][j] > x[i][mx]) mx = j; } s.insert({x[i][mn], i}); s.insert({x[i][mx], i}); a[i] = {mn, mx}; } while (s.size() > 0) { int diff = 0; int idx1 = -1, idx2 = -1; // try min first auto it1 = s.begin(); auto it2 = s.rbegin(); if (it1->second == it2->second) { it2++; } diff = it2->first - it1->first; idx1 = it1->second; idx2 = it2->second; // try max first it1 = s.begin(); it2 = s.rbegin(); if (it1->second == it2->second) { it1++; } if (it2->first - it1->first > diff) { diff = it2->first - it1->first; idx1 = it1->second; idx2 = it2->second; } res += diff; ans[idx1][a[idx1].first] = r; ans[idx2][a[idx2].second] = r; s.erase({x[idx1][a[idx1].first], idx1}); s.erase({x[idx1][a[idx1].second], idx1}); s.erase({x[idx2][a[idx2].first], idx2}); s.erase({x[idx2][a[idx2].second], idx2}); } } allocate_tickets(ans); return res; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...