이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include "tickets.h"
#define DIMN 1510
#define MLD 1000000000
using namespace std;
long long spl[DIMN][DIMN] , spr[DIMN][DIMN];
int prefix[DIMN] , sufix[DIMN];
int f[DIMN];
vector <long long> dp[DIMN] , tt[DIMN];
long long find_maximum(int k, vector<vector<int>> x) {
int n = x.size() , i , j , take , l , r;
int m = x[0].size();
long long sol = 0;
vector<vector<int>> answer;
for (i = 0; i < n; i++) {
vector<int> row;
row.resize(m , -1);
answer.push_back(row);
sufix[i] = m - 1;
}
for (i = 1 ; i <= n ; i++){
for (j = 1 ; j <= m ; j++)
spl[i][j] = x[i - 1][j - 1] + spl[i][j - 1];
for (j = m ; j ; j--)
spr[i][j] = MLD - x[i - 1][j - 1] + spr[i][j + 1];
}
for (i = 0 ; i <= n ; i++){
dp[i].resize(k * n / 2 + 1);
tt[i].resize(k * n / 2 + 1);
}
tt[0][0] = 1;
for (i = 1 ; i <= n ; i++){
for (j = 0 ; j <= k * n / 2 && j <= i * k ; j++){
dp[i][j] = 1000000000000000000LL;
/// cate intre 0 si k iau de aici
for (take = 0 ; take <= j && take <= k ; take++){
if (tt[i - 1][j - take]){
if (dp[i][j] > dp[i - 1][j - take] + spl[i][take] + spr[i][m - (k - take) + 1]){
dp[i][j] = dp[i - 1][j - take] + spl[i][take] + spr[i][m - (k - take) + 1];
tt[i][j] = take + 1;
}
}
}
}
}
sol += 1LL * MLD * k * n / 2 - dp[n][k * n / 2];
i = n;
j = k * n / 2;
int st = 0 , dr = 0;
while (i){
l = tt[i][j] - 1;
for (r = 0 ; r < l ; r++){
answer[i - 1][r] = st;
st = (st + 1) % k;
}
dr = st;
for (r = 0 ; r < k - l ; r++){
answer[i - 1][m - 1 - r] = dr;
dr = (dr + 1) % k;
}
j -= l;
i--;
}
allocate_tickets(answer);
return sol;
}
# | 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... |