Submission #1014319

#TimeUsernameProblemLanguageResultExecution timeMemory
1014319aykhnCarnival Tickets (IOI20_tickets)C++17
0 / 100
1 ms436 KiB
#include "tickets.h" #include <bits/stdc++.h> using namespace std; #define inf 0x3F3F3F3F3F3F3F3F long long find_maximum(int k, vector<vector<int>> x) { assert(k == 1); int n = x.size(); int m = x[0].size(); vector<vector<int>> answer(n, vector<int> (m, -1)); vector<vector<long long>> dp(n, vector<long long> (n / 2 + 5, -inf)), par(n, vector<long long> (n / 2 + 5, -1)); dp[0][0] = -x[0][0], dp[0][1] = x[0][1]; for (int i = 1; i < n; i++) { for (int j = 0; j <= n / 2; j++) { if (j) { if (dp[i - 1][j] - x[i][0] > dp[i - 1][j - 1] + x[i][m - 1]) { dp[i][j] = dp[i - 1][j] - x[i][0]; par[i][j] = j; } else { dp[i][j] = dp[i - 1][j - 1] + x[i][m - 1]; par[i][j] = j - 1; } } else { dp[i][j] = dp[i - 1][j] - x[i][0]; par[i][j] = j; } } } int i = n - 1, j = n / 2; while (i >= 0) { if (!i) { if (j == 1) answer[i][m - 1] = 0; else if (j == 0) answer[i][0] = 0; else assert(0); } else { if (par[i][j] == j) answer[i][0] = 0; else if (par[i][j] == j - 1) answer[i][m - 1] = 0; else assert(0); } j = par[i][j]; i--; } allocate_tickets(answer); return dp[n - 1][n / 2]; }
#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...