Submission #1291690

#TimeUsernameProblemLanguageResultExecution timeMemory
1291690SofiatpcCarnival Tickets (IOI20_tickets)C++20
27 / 100
276 ms66156 KiB
#include "tickets.h" #include <bits/stdc++.h> using namespace std; const int MAXN = 1505; int mn[MAXN], mx[MAXN]; long long dp[MAXN][MAXN]; long long find_maximum(int k, vector<vector<int>> x) { int n = x.size(), m = x[0].size(); vector<vector<int>> ans(n); for (int i = 0; i < n; i++) { ans[i].resize(m); for (int j = 0; j < m; j++)ans[i][j] = -1; } long long resp = 0; for(int kk = 0; kk < k; kk++){ for(int i = 0; i < n; i++){ mn[i] = -1; mx[i] = -1; for(int j = 0; j < m; j++){ if(x[i][j] == -1)continue; if(mn[i] == -1 || x[i][mn[i]] > x[i][j]) mn[i] = j; if(mx[i] == -1 || x[i][mx[i]] < x[i][j]) mx[i] = j; } } dp[n][0] = 0; for(int j = 1; j <= n/2; j++)dp[n][j] = -1e16; for(int i = n-1; i >= 0; i--) for(int j = 0; j <= n/2; j++){ dp[i][j] = -1e16; if(j > 0)dp[i][j] = max(dp[i][j], dp[i+1][j-1] - x[i][mn[i]]); if(n-i-j > 0)dp[i][j] = max(dp[i][j], dp[i+1][j] + x[i][mx[i]]); } int j = n/2; for(int i = 0; i < n; i++){ if(dp[i][j] == dp[i+1][j-1] - x[i][mn[i]]){ ans[i][mn[i]] = kk; x[i][mn[i]] = -1; j--; }else{ ans[i][mx[i]] = kk; x[i][mx[i]] = -1; } } resp += dp[0][n/2]; } allocate_tickets(ans); return resp; }
#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...