제출 #412668

#제출 시각아이디문제언어결과실행 시간메모리
412668dynam1c카니발 티켓 (IOI20_tickets)C++17
27 / 100
620 ms73076 KiB
#include "tickets.h" #include <bits/stdc++.h> using namespace std; typedef long long ll; #define endl "\n" #define all(x) x.begin(),x.end() long long find_maximum(int k, std::vector<std::vector<int>> x) { int n = x.size(); int m = x[0].size(); vector<vector<int>> ans(n, vector<int>(m, -1)); ll res = 0; if (m == 1) { vector<int> arr; for (int i = 0; i < n; i++) ans[i][0] = 0, arr.push_back(x[i][0]); sort(all(arr)); for (int i = 0; i < n; i++) res += arr[i] * (i < n/2 ? -1 : 1); } else if (k == 1) { vector<vector<ll>> dp(n+1, vector<ll>(n/2+1)); // [i][+ count] = best vector<vector<bool>> fl(n+1, vector<bool>(n/2+1)); // [i][+ count] = did you use + here for (int i = 0; i < n; i++) { int mx = x[i].back(); int mn = x[i][0]; dp[i+1][0] = dp[i][0] - mn; for (int j = 1; j <= n/2; j++) { dp[i+1][j] = max(dp[i][j] - mn, dp[i][j-1] + mx); if (dp[i][j-1] + mx >= dp[i][j] - mn) fl[i+1][j] = true; } } int j = n/2; for (int i = n-1; i >= 0; i--) { int e = 0; if (fl[i+1][j]) { e = m-1; j--; } ans[i][e] = 0; } res = dp.back().back(); } 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...