Submission #428439

#TimeUsernameProblemLanguageResultExecution timeMemory
428439MarcoMeijerCarnival Tickets (IOI20_tickets)C++14
39 / 100
3076 ms2097156 KiB
#include "tickets.h" #include <bits/stdc++.h> using namespace std; // macros typedef long long ll; typedef long double ld; typedef pair<int, int> ii; typedef pair<ll, ll> lll; typedef tuple<int, int, int> iii; typedef vector<int> vi; typedef vector<ii> vii; typedef vector<iii> viii; typedef vector<ll> vll; typedef vector<lll> vlll; #define REP(a,b,c) for(int a=int(b); a<int(c); a++) #define RE(a,c) REP(a,0,c) #define RE1(a,c) REP(a,1,c+1) #define REI(a,b,c) REP(a,b,c+1) #define REV(a,b,c) for(int a=int(c-1); a>=int(b); a--) #define FOR(a,b) for(auto& a : b) #define all(a) a.begin(), a.end() #define EPS 1e-9 #define pb push_back #define popb pop_back #define fi first #define se second #define sz size() mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); // output template<class T1, class T2> void OUT(const pair<T1,T2>& x); template<class T> void OUT(const vector<T>& x); template<class T> void OUT(const T& x) {cout << x;} template<class H, class... T> void OUT(const H& h, const T&... t) {OUT(h); OUT(t...); } template<class T1, class T2> void OUT(const pair<T1,T2>& x) {OUT(x.fi,' ',x.se);} template<class T> void OUT(const vector<T>& x) {RE(i,x.size()) OUT(i==0?"":" ",x[i]);} template<class... T> void OUTL(const T&... t) {OUT(t..., "\n"); } template<class H> void OUTLS(const H& h) {OUTL(h); } template<class H, class... T> void OUTLS(const H& h, const T&... t) {OUT(h,' '); OUTLS(t...); } const ll INF = 1e18; ll find_maximum(int k, vector<vi> x) { int n = x.size(); // colors int m = x[0].size(); // tickets per color int N = n*k/2; vector<vi> y = x; RE(i,n) sort(all(y[i])); vector<vll> dp ; // dp [i][j] = maximum sum with the first i colors, and a total of j negative tickets vector<vi > pre; // pre[i][j] = how many negative tickets of color i you should pick to get dp[i][j] dp .assign(n,vll(N+1,-INF)); pre.assign(n,vi (N+1,0)); RE(i,n) { ll tot = 0; RE(l,k) tot += y[i][m-1-l]; int x = m-k; RE(l,k+1) { // take l negative tickets REP(j,l,N+1) { ll nRes = (i ? dp[i-1][j-l] : (j == l ? 0ll : -INF)) + tot; if(nRes > dp[i][j]) { dp [i][j] = nRes; pre[i][j] = l; } } if(l == k) continue; tot -= y[i][l]; tot -= y[i][x++]; } } // reconstruct the answer vector<vi> answer(n,vi(m,-1)); vector<vi> sx(n,vi()); RE(i,n) RE(j,m) sx[i].pb(j); RE(i,n) { sort(all(sx[i]),[&](int a, int b) { return x[i][a] < x[i][b]; }); } vi nextNeg, nextPos; RE(i,n/2) RE(j,k) nextNeg.pb(j); int curNeg = N; REV(i,0,n) { int len = pre[i][curNeg]; vi used; used.assign(k,0); RE(j,len) answer[i][sx[i][j]] = nextNeg.back(), used[nextNeg.back()] = 1, nextNeg.pop_back(); RE(j,k) if(!used[j]) nextPos.pb(j); REP(j,m-k+len,m) answer[i][sx[i][j]] = nextPos.back(), nextPos.pop_back(); curNeg -= len; } allocate_tickets(answer); return dp[n-1][N]; }
#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...