Submission #301937

#TimeUsernameProblemLanguageResultExecution timeMemory
301937VEGAnnCarnival Tickets (IOI20_tickets)C++14
27 / 100
810 ms79228 KiB
#include "tickets.h" #include <bits/stdc++.h> #define PB push_back #define sz(x) ((int)x.size()) #define all(x) x.begin(),x.end() #define i2 array<int,2> using namespace std; typedef long long ll; const int N = 1600; const ll OO = 1e18; ll f[N][N]; int pre[N][N]; long long find_maximum(int k, vector<vector<int>> x) { int n = x.size(); int m = x[0].size(); assert(k == 1); vector<vector<int>> answer; for (int i = 0; i < n; i++) { std::vector<int> row(m); fill(all(row), -1); answer.push_back(row); } for (int i = 0; i < n; i++) for (int j = 0; j <= n; j++) f[i][j] = -OO; f[0][0] = x[0][m - 1]; f[0][1] = -x[0][0]; int n2 = (n >> 1); for (int i = 0; i < n - 1; i++) for (int cnt = 0; cnt <= n2; cnt++){ if (f[i][cnt] == -OO) continue; if (cnt + 1 <= n2 && f[i][cnt] - x[i + 1][0] > f[i + 1][cnt + 1]){ f[i + 1][cnt + 1] = f[i][cnt] - x[i + 1][0]; pre[i + 1][cnt + 1] = cnt; } if (f[i][cnt] + x[i + 1][m - 1] > f[i + 1][cnt]){ f[i + 1][cnt] = f[i][cnt] + x[i + 1][m - 1]; pre[i + 1][cnt] = cnt; } } ll ans = f[n - 1][n2]; int i = n - 1, j = n2; while (i > 0){ int pr = pre[i][j]; if (j == pr){ answer[i][m - 1] = 0; } else { answer[i][0] = 0; } j = pr; i--; } if (j == 1){ answer[0][0] = 0; } else { answer[0][m - 1] = 0; } allocate_tickets(answer); return ans; }
#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...