# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
769127 | t6twotwo | Carnival Tickets (IOI20_tickets) | C++17 | 434 ms | 61664 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "tickets.h"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll find_maximum(int K, vector<vector<int>> x) {
int N = x.size();
int M = x[0].size();
if (M == 1) {
allocate_tickets(vector(N, vector{0}));
vector<int> v(N);
for (int i = 0; i < N; i++) {
v[i] = x[i][0];
}
sort(v.begin(), v.end());
ll s = 0;
for (int i = 0; i < N; i++) {
s += abs(v[N / 2] - v[i]);
}
return s;
}
if (K == 1) {
vector dp(N + 1, vector<ll>(N / 2 + 1, -1e18));
dp[0][0] = 0;
for (int i = 0; i < N; i++) {
for (int j = 0; j <= N / 2; j++) {
if (j < N / 2) {
dp[i + 1][j + 1] = dp[i][j] + x[i][M - 1];
}
dp[i + 1][j] = max(dp[i + 1][j], dp[i][j] - x[i][0]);
}
}
vector ans(N, vector<int>(M, -1));
for (int i = N - 1, j = N / 2; i >= 0; i--) {
if (dp[i][j] - x[i][0] == dp[i + 1][j]) {
ans[i][0] = 0;
} else {
ans[i][M - 1] = 0;
j--;
}
}
allocate_tickets(ans);
return dp[N][N / 2];
}
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |