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;
#define int ll
#define fast_io ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define pb push_back
#define re resize
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
#define loop(i, n) for(int i = 0; i < n; i++)
#define loop1(i, n) for(int i = 1; i <= n; i++)
#define print(x) cout << #x << ": " << x << endl << flush
typedef long long ll;
typedef vector<int> vi;
typedef array<int, 2> ii;
typedef array<int, 3> ti;
typedef vector<ii> vii;
typedef vector<ti> vti;
typedef vector<vi> vvi;
typedef priority_queue<int> pq;
template<class T> bool ckmin(T&a, T b) { bool B = a > b; a = min(a, b); return B; }
template<class T> bool ckmax(T&a, T b) { bool B = a < b; a = max(a, b); return B; }
const int inf = 1e17;
const int maxn = 1505;
ii dp[maxn][maxn];
long long find_maximum(signed k, vector<vector<signed>> x) {
int n = x.size();
int m = x[0].size();
if(false) {
vi v;
loop(i, n) v.pb(x[i][0]);
sort(all(v));
int res = 0;
loop(i, n/2) res -= v[i];
loop(i, n/2) res += v[n/2 + i];
vector<vector<signed>> answer;
vector<signed> row(1, 0);
loop(i, n) answer.pb(row);
allocate_tickets(answer);
return res;
} else if(k == 1) {
vi high(1), low(1);
loop(i, n) {
high.pb(*max_element(all(x[i])));
low.pb(*min_element(all(x[i])));
}
loop1(i, n) loop(j, i+1) { dp[i][j] = {-inf, 0}; }
loop1(i, n) loop(j, i+1) {
if(i-1 >= j) ckmax(dp[i][j], {dp[i-1][j][0] + high[i], 1});
if(j > 0 and i-1 >= j-1) ckmax(dp[i][j], {dp[i-1][j-1][0] - low[i], -1});
}
vi taken(n+1);
int j = n/2;
for(int i = n; i >= 1; i--) {
taken[i] = dp[i][j][1];
if(taken[i] == -1) { j--; }
}
vector<vector<signed>> answer(n, vector<signed>(m, -1));
loop1(i, n) {
int idx = -1;
if(taken[i] == -1) idx = min_element(all(x[i-1])) - x[i-1].begin();
if(taken[i] == +1) idx = max_element(all(x[i-1])) - x[i-1].begin();
answer[i-1][idx] = 0;
}
allocate_tickets(answer);
return dp[n][n/2][0];
}
return 1;
}
# | 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... |