Submission #307058

#TimeUsernameProblemLanguageResultExecution timeMemory
307058rqiCarnival Tickets (IOI20_tickets)C++14
0 / 100
1 ms384 KiB
#include "tickets.h" #include <bits/stdc++.h> using namespace std; typedef pair<int, int> pi; typedef vector<int> vi; typedef long long ll; typedef vector<ll> vl; typedef pair<ll, ll> pl; typedef vector<pi> vpi; typedef vector<pl> vpl; #define pb push_back #define sz(x) (int)(x).size() #define all(x) begin(x), end(x) #define mp make_pair #define f first #define s second #define bk back() vi goods[1505]; priority_queue<pi> szs; //size, index long long find_maximum(int k, vector<vi> x) { int n = sz(x); int m = sz(x[0]); vector<vi> answer; for(int i = 0; i < n; i++){ answer.pb(vi(m, -1)); } ll ans = 0; if(k == m){ vector<pair<int, pi>> inds; for(int i = 0; i < n; i++){ for(int j = 0; j < m; j++){ inds.pb(mp(x[i][j], mp(i, j))); ans-=x[i][j]; } } sort(all(inds)); for(int i = (n/2)*m; i < n*m; i++){ goods[inds[i].s.f].pb(inds[i].s.s); ans+=2*inds[i].f; } for(int i = 0; i < n; i++){ szs.push(mp(sz(goods[i]), i)); } for(int round = 0; round < k; round++){ vpi trash; for(int i = 0; i < n/2; i++){ pi a = szs.top(); szs.pop(); answer[a.s][goods[a.s].bk] = round; goods[a.s].pop_back(); trash.pb(mp(a.f-1, a.s)); } for(auto u: trash){ szs.push(u); } } while(sz(szs)) szs.pop(); for(int i = 0; i < (n/2)*m; i++){ goods[inds[i].s.f].pb(inds[i].s.s); ans+=2*inds[i].f; } for(int i = 0; i < n; i++){ szs.push(mp(sz(goods[i]), i)); } for(int round = 0; round < k; round++){ vpi trash; for(int i = 0; i < n/2; i++){ pi a = szs.top(); szs.pop(); answer[a.s][goods[a.s].bk] = round; goods[a.s].pop_back(); trash.pb(mp(a.f-1, a.s)); } for(auto u: trash){ szs.push(u); } } } 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...