제출 #592110

#제출 시각아이디문제언어결과실행 시간메모리
592110farhan132카니발 티켓 (IOI20_tickets)C++17
100 / 100
785 ms117956 KiB
#include "tickets.h" #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll , ll> ii; #define ff first #define ss second #define pb push_back #define in insert long long find_maximum(int k, std::vector<std::vector<int>> x) { ll n = x.size(); ll m = x[0].size(); vector < vector < int > > answer(n, vector < int >(m, -1)); vector < vector < int > > neg(n, vector < int >(m, 0)); vector < vector < int > > pos(n, vector < int >(m, 0)); vector < ll > curX(n, k-1); vector < ll > curY(n, m); ll ans = 0; priority_queue < ii > p; for(ll i = 0; i < n; i++){ for(ll j = 0; j < m; j++){ if(j < k) neg[i][j] = 1, ans -= x[i][j]; } if(curX[i] >= 0){ p.push({x[i][curX[i]] + x[i][curY[i] - 1], i}); } } for(ll itr = 0; itr < (k * n)/2; itr++){ auto [value, i] = p.top(); p.pop(); ans += value; neg[i][curX[i]] = 0; pos[i][curY[i] - 1] = 1; curY[i]--; curX[i]--; if(curX[i] >= 0){ p.push({x[i][curX[i]] + x[i][curY[i] - 1], i}); } } vector < ll > P[n + 10], N[n + 10]; for(ll i = 0; i < n; i++){ for(ll j = 0; j < m; j++){ if(neg[i][j]) N[i].pb(j); if(pos[i][j]) P[i].pb(j); } } for(ll itr = 0; itr < k; itr++){ ll tot = 0; vector < ll > done(n, 0); for(ll i = 0; i < n; i++){ if(!N[i].size()){ auto T = P[i].back(); P[i].pop_back(); answer[i][T] = itr; done[i] = 1; tot++; }else if(!P[i].size()){ auto T = N[i].back(); N[i].pop_back(); answer[i][T] = itr; done[i] = 1; } } for(ll i = 0; i < n; i++){ if(done[i]) continue; if(tot < n/2){ auto T = P[i].back(); P[i].pop_back(); answer[i][T] = itr; done[i] = 1; tot++; }else{ auto T = N[i].back(); N[i].pop_back(); answer[i][T] = itr; done[i] = 1; } } } allocate_tickets(answer); 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...