Submission #300952

#TimeUsernameProblemLanguageResultExecution timeMemory
300952lohachoCarnival Tickets (IOI20_tickets)C++14
100 / 100
1114 ms78776 KiB
#include "tickets.h" #include <bits/stdc++.h> using namespace std; const int INF = (int)2e9; using LL = long long; int L[2004]; vector < int > dif[2004]; priority_queue < pair < int, int > > big, low; int pos[2004]; vector < int > use_l[2004], use_r[2004]; vector < int > zero; long long find_maximum(int k, std::vector<std::vector<int>> x) { int N = x.size(); int M = x[0].size(); std::vector<std::vector<int>> answer; answer.resize(N); LL sum = 0; for(int i = 0; i < N / 2; ++i){ answer[i].resize(M); L[i] = k; for(int j = k - 1; j >= 0; --j){ sum -= x[i][j]; dif[i].push_back(x[i][M - (k - j)] + x[i][j]); } dif[i].push_back(-INF); big.push(make_pair(dif[i][0], i)); } for(int i = N / 2; i < N; ++i){ answer[i].resize(M); L[i] = 0; for(int j = M - k; j < M; ++j){ sum += x[i][j]; dif[i].push_back(-x[i][j] - x[i][j - (M - k)]); } dif[i].push_back(-INF); low.push(make_pair(dif[i][0], i)); } while(1){ auto b = big.top(), l = low.top(); big.pop(), low.pop(); LL val = (LL)b.first + l.first; if(val <= 0){ break; } sum += val; ++pos[b.second], big.push(make_pair(dif[b.second][pos[b.second]], b.second)); --L[b.second]; ++pos[l.second], low.push(make_pair(dif[l.second][pos[l.second]], l.second)); ++L[l.second]; } for(int i = 0; i < N; ++i){ for(int j = 0; j < L[i]; ++j){ use_l[i].push_back(j); } for(int j = M - k + L[i]; j < M; ++j){ use_r[i].push_back(j); } if(L[i] == k) zero.push_back(i); } for(int i = 0; i < N; ++i){ for(int j = 0; j < M; ++j){ answer[i][j] = -1; } } for(int i = 0; i < k; ++i){ int cnt = 0; for(auto&j:zero){ ++cnt; answer[j][use_l[j].back()] = i; use_l[j].pop_back(); } for(int j = 0; j < N; ++j){ if(!(int)use_r[j].size()) continue; if(cnt < N / 2 && (int)use_l[j].size()){ ++cnt; answer[j][use_l[j].back()] = i; use_l[j].pop_back(); } else{ answer[j][use_r[j].back()] = i; use_r[j].pop_back(); if((int)use_r[j].size() == 0){ zero.push_back(j); } } } } allocate_tickets(answer); 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...