제출 #622824

#제출 시각아이디문제언어결과실행 시간메모리
622824someone카니발 티켓 (IOI20_tickets)C++14
100 / 100
858 ms97048 KiB
#include "tickets.h" #include <bits/stdc++.h> using namespace std; using ll = long long; ll find_maximum(int k, vector<vector<int>> x) { ll n = x.size(), m = x[0].size(), sum = 0, need = k*n/2, id[n]; int chosen[n][m]; for(int i = 0; i < n; i++) for(int j = 0; j < m; j++) chosen[i][j] = 0; vector<vector<int>> s(n); priority_queue<pair<ll, ll>> change; for(int i = 0; i < n; i++) { id[i] = m-k; s[i].resize(m); sort(x[i].begin(), x[i].end()); for(int j = 0; j < m; j++) s[i][j] = -1; for(int j = id[i]; j < m; j++) { sum += x[i][j]; chosen[i][j] = 1; } change.push({- x[i][0] - x[i][m-k], i}); } while(need--) { pair<ll, ll> pii = change.top(); change.pop(); sum += pii.first; ll lig = pii.second, rempl = id[lig] - (m-k); chosen[lig][rempl] = -1; if(rempl != id[lig]) chosen[lig][id[lig]] = 0; id[lig]++; if(id[lig] < m) change.push({- x[lig][id[lig] - (m-k)] - x[lig][id[lig]], lig}); } vector<int> inf[n], sup[n]; for(int i = 0; i < n; i++) for(int j = 0; j < m; j++) if(chosen[i][j] == 1) sup[i].push_back(j); else if(chosen[i][j] == -1) inf[i].push_back(j); int mid = n/2; for(int i = 0; i < k; i++) { pair<int, int> iLig[n]; for(int j = 0; j < n; j++) iLig[j] = {sup[j].size(), j}; sort(iLig, iLig + n); for(int j = 0; j < mid; j++) { int lig = iLig[j].second; s[lig][inf[lig].back()] = i; inf[lig].pop_back(); } for(int j = mid; j < n; j++) { int lig = iLig[j].second; s[lig][sup[lig].back()] = i; sup[lig].pop_back(); } } allocate_tickets(s); return sum; }
#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...