제출 #301102

#제출 시각아이디문제언어결과실행 시간메모리
301102Khongor카니발 티켓 (IOI20_tickets)C++14
11 / 100
4 ms768 KiB
#include "tickets.h" #include <bits/stdc++.h> using namespace std; vector<vector<int>> ans; // 1 5 // 10 10 // 8 12 // 12 20 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++) { set<pair<int, int>> low, high; 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; } low.insert({x[i][mn], i}); high.insert({x[i][mx], i}); a[i] = {mn, mx}; } vector<int> v; while (low.size() > 0) { int diff = 0; int idx1 = -1, idx2 = -1; // try min first auto it1 = low.begin(); auto it2 = high.rbegin(); if (it1->second == it2->second) { it2++; } assert(it2->first >= it1->first); diff = it2->first - it1->first; idx1 = it1->second; idx2 = it2->second; // try max first it1 = low.begin(); it2 = high.rbegin(); if (it1->second == it2->second) { it1++; } assert(it2->first >= it1->first); if (it2->first - it1->first > diff) { diff = it2->first - it1->first; idx1 = it1->second; idx2 = it2->second; } ans[idx1][a[idx1].first] = r; ans[idx2][a[idx2].second] = r; v.push_back(it1->first); v.push_back(it2->first); low.erase({x[idx1][a[idx1].first], idx1}); low.erase({x[idx2][a[idx2].first], idx2}); high.erase({x[idx1][a[idx1].second], idx1}); high.erase({x[idx2][a[idx2].second], idx2}); } sort(v.begin(), v.end()); for (int i = 0; i < ((int)v.size() - 1 - i); i++) { res += v[v.size() - 1 - i] - v[i]; } } 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...