Submission #303438

#TimeUsernameProblemLanguageResultExecution timeMemory
303438baluteshihCarnival Tickets (IOI20_tickets)C++14
62 / 100
2079 ms2097156 KiB
#include "tickets.h" #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int,int> pii; typedef pair<ll,ll> pll; #define X first #define Y second #define ALL(v) v.begin(),v.end() #define SZ(a) ((int)a.size()) #define pb push_back const ll INF=1e18; ll find_maximum(int k, vector<vector<int>> x) { int n = x.size(); int m = x[0].size(); int tar=n*k/2; vector<vector<ll>> dp(n+1,vector<ll>(tar+1,-INF)),take(n+1,vector<ll>(k+1,0)); vector<vector<int>> answer(n,vector<int>(m,-1)); vector<int> cnt(n,0),num(n,0),nw(n,0),tp(n,0); for(int i=1;i<=n;++i) { for(int j=0;j<k;++j) take[i][0]-=x[i-1][j]; for(int j=1;j<=k;++j) take[i][j]=take[i][j-1]+x[i-1][k-j]+x[i-1][m-j]; } dp[0][tar]=0; for(int i=1;i<=n;++i) for(int j=0,t=k;j<=tar;++j) { while(t>0&&(j+t>tar||dp[i-1][j+t]+take[i][t]<=dp[i-1][j+t-1]+take[i][t-1])) --t; dp[i][j]=dp[i-1][j+t]+take[i][t]; //for(int t=0;t<=k&&j+t<=tar;++t) // dp[i][j]=max(dp[i][j],dp[i-1][j+t]+take[i][t]); } int nxt=0; /*for(int i=1;i<=n;++i) for(int j=0;j<=tar;++j) { int frm=0; for(int t=0;t<=k&&j+t<=tar;++t) if(dp[i][j]==dp[i-1][j+t]+take[i][t]) { frm=t; break; } cout << frm << " \n"[j==tar]; }*/ for(int i=n;i>=1;--i) { for(int t=0;t<=k;++t) if(dp[i][nxt]==dp[i-1][nxt+t]+take[i][t]) { cnt[i-1]=t; nxt+=t; break; } } for(int i=0;i<n;++i) nw[i]=k-cnt[i],num[i]=i,tp[i]=cnt[i]; for(int i=0;i<k;++i) { sort(ALL(num),[&](int a,int b){return cnt[a]>cnt[b];}); for(int j=0;j<n/2;++j) answer[num[j]][m-tp[num[j]]+(--cnt[num[j]])]=i; for(int j=n/2;j<n;++j) answer[num[j]][--nw[num[j]]]=i; } allocate_tickets(answer); return dp[n][0]; }
#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...