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 <vector>
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1510;
int N, M, mat[2][maxn], dp[maxn][maxn], nxt[maxn][maxn]; // min e max, 0 e 1
long long solve(int row, int qtd){
if(row == N) return 0;
if(dp[row][qtd] != -1) return dp[row][qtd];
if(qtd == 0) dp[row][qtd] = -mat[0][row] + solve(row+1, qtd), nxt[row][qtd] = qtd;
else if(N-1-row == qtd) dp[row][qtd] = mat[1][row] + solve(row+1, qtd-1), nxt[row][qtd] = qtd-1;
else{
long long caso1 = mat[1][row] + solve(row+1, qtd-1);
long long caso2 = -mat[0][row] + solve(row+1, qtd);
if(caso1 > caso2){
dp[row][qtd] = caso1;
nxt[row][qtd] = qtd-1;
}
else{
dp[row][qtd] = caso2;
nxt[row][qtd] = qtd;
}
}
return dp[row][qtd];
}
long long find_maximum(int k, vector<vector<int>> x) {
N = x.size(), M = x[0].size();
vector<vector<int>> answer;
for(int i=0; i<N; i++){
vector<int> row(M);
for(int j=0; j<M; j++) row[j] = -1;
answer.push_back(row);
mat[0][i] = x[i][0];
mat[1][i] = x[i][M-1];
}
memset(dp, -1, sizeof dp);
long long ans = solve(0, N/2);
int qtd = N/2;
for(int r=0; r<N; r++){
if(nxt[r][qtd] == qtd) answer[r][0] = 0;
else{
answer[r][M-1] = 0;
qtd--;
}
}
allocate_tickets(answer);
return ans;
/*
4 2 1
5 9
1 4
3 6
2 7
*/
}
# | 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... |