제출 #684145

#제출 시각아이디문제언어결과실행 시간메모리
684145sharaelong카니발 티켓 (IOI20_tickets)C++17
100 / 100
1287 ms114988 KiB
#include "tickets.h" #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; ll find_maximum(int k, vector<vector<int>> x) { int n = x.size(); int m = x[0].size(); vector<int> max_val_cnt(n, 0); priority_queue<pii> pq; for (int i=0; i<n; ++i) { for (int j=0; j<k; ++j) { pq.push({ x[i][k-1-j] + x[i][m-1-j], i }); } } for (int i=0; i<n*k/2; ++i) { auto[_, idx] = pq.top(); pq.pop(); max_val_cnt[idx]++; } vector<pii> effective_tickets; for (int i=0; i<n; ++i) { for (int j=0; j<max_val_cnt[i]; ++j) effective_tickets.push_back({ m-1-j, i }); for (int j=0; j<k-max_val_cnt[i]; ++j) effective_tickets.push_back({ j, i }); } sort(effective_tickets.begin(), effective_tickets.end(), [&](const pii& a, const pii& b) { return x[a.second][a.first] < x[b.second][b.first]; }); ll ans_val = 0; vector<vector<int>> ans(n, vector<int>(m, -1)); vector<vector<int>> plus_elem(n); vector<vector<int>> minus_elem(n); for (int i=0; i<n*k/2; ++i) { auto[j, idx] = effective_tickets[i]; ans_val -= x[idx][j]; minus_elem[idx].push_back(j); auto[j2, idx2] = effective_tickets[n*k-1-i]; ans_val += x[idx2][j2]; plus_elem[idx2].push_back(j2); } for (int i=0; i<k; ++i) { vector<pii> plus_freq; for (int j=0; j<n; ++j) plus_freq.push_back({ plus_elem[j].size(), j }); sort(plus_freq.begin(), plus_freq.end()); for (int j=0; j<n/2; ++j) { int idx = plus_freq[j].second; ans[idx][minus_elem[idx].back()] = i; minus_elem[idx].pop_back(); } for (int j=n/2; j<n; ++j) { int idx = plus_freq[j].second; ans[idx][plus_elem[idx].back()] = i; plus_elem[idx].pop_back(); } } allocate_tickets(ans); return ans_val; }
#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...