제출 #609629

#제출 시각아이디문제언어결과실행 시간메모리
609629Jarif_Rahman카니발 티켓 (IOI20_tickets)C++17
100 / 100
688 ms56576 KiB
#include "tickets.h" #include <bits/stdc++.h> #define pb push_back #define f first #define sc second using namespace std; typedef long long int ll; typedef string str; ll find_maximum(int K, vector<vector<int>> v){ int n = v.size(), m = v[0].size(); vector<vector<int>> pos(n, vector<int>(m, -1)); ll ans = 0; vector<vector<bool>> plus(n, vector<bool>(m, 0)); for(int i = 0; i < n; i++) for(int j = m-1; j >= m-K; j--) ans+=v[i][j], plus[i][j] = 1; priority_queue<pair<ll, pair<int, int>>> pq; for(int i = 0; i < n; i++) pq.push({-v[i][0]-v[i][m-K], {i, 0}}); for(int I = 0; I < (n*K)/2; I++){ auto [x, ij] = pq.top(); pq.pop(); auto [i, j] = ij; plus[i][m-K+j] = 0; ans+=x; if(j != K-1) pq.push({-v[i][j+1]-v[i][m-K+j+1], {i, j+1}}); } vector<int> cnt(n), o(n); for(int i = 0; i < n; i++) cnt[i] = count(plus[i].begin(), plus[i].end(), 1); for(int i = 0; i < n; i++) o[i] = i; vector<int> L(n, 0), R(n, m-1); for(int k = 0; k < K; k++){ sort(o.begin(), o.end(), [&cnt](int a, int b){ return cnt[a] < cnt[b]; }); for(int j = 0, i = o[0]; j < n/2; j++, i = o[j]){ pos[i][L[i]] = k; if(plus[i][L[i]]) cnt[i]--; L[i]++; } for(int j = n/2, i = o[n/2]; j < n; j++, i = o[j]){ pos[i][R[i]] = k; if(plus[i][R[i]]) cnt[i]--; R[i]--; } } allocate_tickets(pos); return ans; }
#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...