제출 #301959

#제출 시각아이디문제언어결과실행 시간메모리
301959VEGAnn카니발 티켓 (IOI20_tickets)C++14
16 / 100
743 ms79080 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> #define i3 array<int,3> using namespace std; typedef long long ll; const int N = 1600; const ll OO = 1e18; vector<i3> vc; 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(); vector<vector<int>> answer; for (int i = 0; i < n; i++) { std::vector<int> row(m); fill(all(row), -1); answer.push_back(row); } if (k == m){ ll ans = 0; for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) vc.PB({x[i][j], i, j}); sort(all(vc)); for (int i = 0; i < sz(vc); i++) if (i < sz(vc) / 2) ans -= vc[i][0]; else ans += vc[i][0]; return ans; } 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...