이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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 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... |