제출 #578215

#제출 시각아이디문제언어결과실행 시간메모리
578215jeroenodb카니발 티켓 (IOI20_tickets)C++17
100 / 100
744 ms75240 KiB
#include "tickets.h" #include <vector> #include "bits/stdc++.h" using namespace std; #define all(x) begin(x),end(x) template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; } template<typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type> ostream& operator<<(ostream &os, const T_container &v) { string sep; for (const T &x : v) os << sep << x, sep = " "; return os; } #define debug(a) cerr << "(" << #a << ": " << a << ")\n"; typedef long long ll; typedef vector<int> vi; typedef vector<vi> vvi; typedef pair<int,int> pi; const int mxN = 1e5+1, oo = 1e9; long long find_maximum(int k, std::vector<std::vector<int>> x) { ll ans=0; int n = x.size(),m = x[0].size(); vi big(n); struct el { int dif,color; bool operator<(const el& o) { return dif>o.dif; } }; vector<el> options; for(int col=0;col<n;++col) { auto& v = x[col]; for(int i=0;i<k;++i) ans-=v[i]; for(int i=0;i<k;++i) { options.push_back({v[k-1-i]+v[m-1-i],col}); } } sort(all(options)); options.resize(n*k/2); for(auto e : options) { big[e.color]++; ans+=e.dif; } vi small(n,m-1); for(int i=0;i<n;++i) small[i]=k-big[i]; // construct it for(auto& v : x) fill(all(v),-1); for(int i=0;i<k;++i) { vector<bool> vis(n); int bal=0; auto take=[&](int j) { if(vis[j]) return; vis[j]=true; if(small[j]!=0 and (big[j]==0 or bal>0)) { bal--; x[j][--small[j]] = i; } else { x[j][m - big[j]--] = i; bal++; } }; for(int j=0;j<n;++j) { if(big[j]==0 or small[j]==0) { take(j); } } for(int j=0;j<n;++j) take(j); } allocate_tickets(x); 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...