Submission #489717

#TimeUsernameProblemLanguageResultExecution timeMemory
4897178e7카니발 티켓 (IOI20_tickets)C++17
0 / 100
1 ms332 KiB
#include "tickets.h" //Challenge: Accepted #include <iostream> #include <algorithm> #include <vector> #include <utility> #include <random> #include <chrono> using namespace std; void debug(){cout << endl;} template<class T, class ...U> void debug(T a, U ... b){cout << a << " ", debug(b...);} template<class T> void pary (T l, T r) { while (l != r) cout << *l << " ", l++; cout << endl; } #define ll long long #define maxn 85 #define pii pair<int, int> #define ff first #define ss second const ll inf = 1LL<<60; ll dp[maxn][maxn*maxn], cost[maxn][maxn]; int prv[maxn][maxn*maxn], pref[maxn], suf[maxn]; long long find_maximum(int k, vector<vector<int> > x) { int n = x.size(); int m = x[0].size(); ll tot = 0; for (int i = 0;i < n;i++) { for (int j = m - k;j < m;j++) { tot += x[i][j]; cost[i][j - m + k + 1] = -x[i][j - m + k] - x[i][j]; } for (int j = 1;j <= k;j++) cost[i][j] += cost[i][j-1]; //pary(cost[i], cost[i] + k + 1); } vector<vector<int> > ans(n, vector<int>(m, -1)); for (int j = 0;j <= n;j++) { for (int i = 1;i <= n * k;i++) dp[j][i] = -inf; } for (int i = 0; i < n; i++) { for (int j = 0; j <= k; j++) { for (int c = 0;c <= n * k / 2 - j;c++) { ll val = dp[i][c] + cost[i][j]; if (val > dp[i+1][j+c]) { dp[i+1][j+c] = val; prv[i+1][j+c] = j; } } } } int cur = n * k / 2; for (int i = n;i > 0;i--) { pref[i-1] = prv[i][cur]; suf[i-1] = n - (k - pref[i-1]); cur -= prv[i][cur]; } for (int ti = 0;ti < k;ti++) { int rem = n / 2; for (int i = 0;i < n;i++) { if (pref[i] && rem) { rem--; pref[i]--; ans[i][pref[i]] = ti; } else { suf[i]++; ans[i][suf[i]] = ti; } } } allocate_tickets(ans); //debug(tot, dp[n][n*k/2]); return tot + dp[n][n*k/2]; } /* 2 3 2 0 2 5 1 1 3 */
#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...