Submission #307296

#TimeUsernameProblemLanguageResultExecution timeMemory
307296rqiCarnival Tickets (IOI20_tickets)C++14
100 / 100
1342 ms73096 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]; vi bads[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; for(int i = 0; i < n; i++){ for(int j = 0; j < k; j++){ bads[i].pb(j); ans-=x[i][j]; } szs.push(mp(x[i][bads[i].bk]+x[i][bads[i].bk+m-k], i)); } int cnt = 0; while(cnt < (n/2)*k){ pi a = szs.top(); szs.pop(); ans+=a.f; goods[a.s].pb(bads[a.s].bk+m-k); bads[a.s].pop_back(); if(sz(bads[a.s]) >= 1){ szs.push(mp(x[a.s][bads[a.s].bk]+x[a.s][bads[a.s].bk+m-k], a.s)); } cnt++; } priority_queue<pi> emp; swap(szs, emp); 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(int i = 0; i < n/2; i++){ pi a = szs.top(); szs.pop(); answer[a.s][bads[a.s].bk] = round; bads[a.s].pop_back(); trash.pb(a); } for(auto u: trash){ szs.push(u); } } allocate_tickets(answer); return ans; // 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 = 0; i < (n/2)*m; i++){ // bads[inds[i].s.f].pb(inds[i].s.s); // } // 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(int i = 0; i < n/2; i++){ // pi a = szs.top(); // szs.pop(); // //cout << a.s << "\n"; // answer[a.s][bads[a.s].bk] = round; // bads[a.s].pop_back(); // trash.pb(a); // } // 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...