#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] = m - (k - pref[i-1]);
cur -= prv[i][cur];
//debug(i-1, pref[i-1], suf[i-1]);
}
int ord[n];
for (int i = 0;i < n;i++) ord[i] = i;
sort(ord, ord + n, [&](int x, int y){return pref[x] > pref[y];});
for (int ti = 0;ti < k;ti++) {
int rem = n / 2;
for (int j = 0;j < n;j++) {
int i = ord[j];
if (pref[i] && rem) {
rem--;
pref[i]--;
ans[i][pref[i]] = ti;
} else {
ans[i][suf[i]] = ti;
suf[i]++;
}
}
}
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
4 2 1
5 9
1 4
3 6
2 7
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
972 KB |
Output is correct |
5 |
Runtime error |
2 ms |
1868 KB |
Execution killed with signal 11 |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
0 ms |
332 KB |
Output is correct |
4 |
Correct |
2 ms |
1100 KB |
Output is correct |
5 |
Runtime error |
12 ms |
4044 KB |
Execution killed with signal 11 |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
304 KB |
Output is correct |
3 |
Correct |
0 ms |
332 KB |
Output is correct |
4 |
Incorrect |
6 ms |
3532 KB |
There is no ticket of color 50 on day 34 |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Runtime error |
1 ms |
668 KB |
Execution killed with signal 6 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
2 ms |
1228 KB |
Output is correct |
3 |
Incorrect |
2 ms |
1356 KB |
There is no ticket of color 15 on day 2 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
2 ms |
1228 KB |
Output is correct |
3 |
Incorrect |
2 ms |
1356 KB |
There is no ticket of color 15 on day 2 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
972 KB |
Output is correct |
5 |
Runtime error |
2 ms |
1868 KB |
Execution killed with signal 11 |
6 |
Halted |
0 ms |
0 KB |
- |