Submission #1004705

#TimeUsernameProblemLanguageResultExecution timeMemory
1004705ArapakCarnival Tickets (IOI20_tickets)C++17
100 / 100
535 ms71956 KiB
// Author: Kajetan Ramsza #include "bits/stdc++.h" #include "tickets.h" using namespace std; #define rep(i, a, b) for(int i = (a); i < (b); ++i) #define all(x) begin(x), end(x) #define sz(x) (int)(x).size() typedef long long ll; typedef pair<int, int> pii; typedef vector<int> vi; template<typename F, typename S> ostream& operator<<(ostream& os, const pair<F, S> &p) { return os<<"("<<p.first<<", "<<p.second<<")"; } template<typename T> ostream &operator<<(ostream & os, const vector<T> &v) { os << "{"; typename vector< T > :: const_iterator it; for( it = v.begin(); it != v.end(); it++ ) { if( it != v.begin() ) os << ", "; os << *it; } return os << "}"; } void dbg_out() { cerr<<'\n'; } template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr<<' '<<H; dbg_out(T...); } #ifdef DEBUG #define dbg(...) cerr<<"(" << #__VA_ARGS__ <<"):", dbg_out(__VA_ARGS__) #else #define dbg(...) #endif const ll inf = ll(1e18) + 7; int n, m, k; vector<vi> answer; vi used; vector<vector<ll>> tickets; void fill_ans() { vector<vi> ones(n); vector<vi> zeros(n); rep(i,0,n) rep(j,0,m) { if(j <= k - used[i]) zeros[i].push_back(j); else if(j > m - used[i]) ones[i].push_back(j); } dbg(ones); dbg(zeros); rep(ind,0,k) { vector<pii> num(n); rep(i,0,n) num[i] = {sz(ones[i]), i}; sort(all(num)); rep(i,0,n) { int index = num[i].second; if((i < n/2 && sz(zeros[index])) || sz(ones[index]) == 0) { answer[index][zeros[index].back()] = ind; zeros[index].pop_back(); } else { answer[index][ones[index].back()] = ind; ones[index].pop_back(); } } } } ll solve() { used.assign(n, 1); ll res = 0; rep(i,0,n) rep(j,0,k) res -= tickets[i][j]; priority_queue<pair<ll, int>> q; rep(i,0,n) q.push({tickets[i][m-1] + tickets[i][k-1], i}); rep(i,0,n*k/2) { auto [val, ind] = q.top(); dbg(val, ind); q.pop(); res += val; used[ind]++; if(used[ind] <= k) q.push({tickets[ind][m-used[ind]] + tickets[ind][k-used[ind]], ind}); } fill_ans(); return res; } ll find_maximum(int k_, vector<vi> tickets_) { k = k_; n = tickets_.size(); m = tickets_[0].size(); tickets.assign(n, vector<ll>(m)); rep(i,0,n) rep(j,0,m) tickets[i][j] = tickets_[i][j]; answer.assign(n, vi(m, -1)); ll res; res = solve(); allocate_tickets(answer); return res; }
#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...