Submission #1059171

#TimeUsernameProblemLanguageResultExecution timeMemory
1059171LalicCarnival Tickets (IOI20_tickets)C++17
27 / 100
267 ms51288 KiB
#include "tickets.h" #include <bits/stdc++.h> using namespace std; #define fi first #define se second #define pb push_back #define all(x) x.begin(), x.end() #define allr(x) x.rbegin(), x.rend() #define mp make_pair typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef complex<double> cd; ll find_maximum(int k, vector<vector<int>> x) { int n = x.size(); int m = x[0].size(); vector<vector<int>> ans(n, vector<int>(m, -1)); vector<int> low(n, 0), high(n, m-1); ll res=0ll; for(int round=0;round<k;round++){ vector<vector<ll>> dp(n, vector<ll>(n/2+1, -1e17)); vector<vector<pii>> prev(n, vector<pii>(n/2+1)); dp[0][0]=x[0][high[0]]; prev[0][0]={-1, 0}; dp[0][1]=-x[0][low[0]]; prev[0][1]={-1, 0}; for(int i=1;i<n;i++){ for(int j=n/2;j>=0;j--){ dp[i][j]=dp[i-1][j]+x[i][high[i]]; prev[i][j]={i-1, j}; if(j && dp[i-1][j-1]-x[i][low[i]]>dp[i][j]){ dp[i][j]=dp[i-1][j-1]-x[i][0]; prev[i][j]={i-1, j-1}; } } } pii curr={n-1, n/2}; while(curr.fi!=-1){ pii ant=prev[curr.fi][curr.se]; if(ant.se==curr.se) ans[curr.fi][high[curr.fi]--]=round; else ans[curr.fi][low[curr.fi]++]=round; curr=ant; } res+=dp[n-1][n/2]; } allocate_tickets(ans); 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...