이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "tickets.h"
#include "bits/stdc++.h"
using namespace std;
long long find_maximum(int k, std::vector<std::vector<int>> x) {
int n = x.size();
int m = x[0].size();
std::vector<std::vector<int>> answer;
for (int i = 0; i < n; i++) {
std::vector<int> row(m);
for (int j = 0; j < m; j++) {
row[j] = -1;
}
answer.push_back(row);
}
long long ps[n+1][m+1];
for(int i=0; i<=n; i++) {
for(int j=0; j<=m; j++) {
ps[i][j] = 0;
}
}
for(int i=1; i<=n; i++) {
for(int j=1; j<=m; j++) {
ps[i][j] = ps[i][j-1] + x[i-1][j-1];
}
}
long long dp[n+1][n*k/2 + 1];
for(int i=0; i<=n; i++) {
for(int j=0; j<=n*k/2; j++) {
dp[i][j] = -1e16;
}
}
dp[0][0] = 0;
for(int i=1; i<=n; i++) {
for(int j=0; j<=n*k/2; j++) {
for(int elev=0; elev<=min(j, k); elev++) {
dp[i][j] = max(dp[i][j], dp[i-1][j - elev] - ps[i][k-elev] + ps[i][m] - ps[i][m-elev]);
}
}
}
int cur = n*k/2;
for(int i=n; i>=1; i--) {
for(int elev=0; elev<=min(cur, k); elev++) {
if(dp[i-1][cur-elev] - ps[i][k-elev] + ps[i][m] - ps[i][m-elev] == dp[i][cur]) {
for(int j=m-elev; j<m; j++) answer[i-1][j] = 1; // to add
for(int j=0; j<k-elev; j++) answer[i-1][j] = -2; // to subtract
cur -= elev;
break;
}
}
}
int nxt = 0;
for(int i=0; i<n; i++) {
for(int j=0; j<m; j++) {
if(answer[i][j] == 1) {
answer[i][j] = nxt;
nxt = (nxt + 1) % k;
}
}
}
for(int i=0; i<n; i++) {
bool bruh[m];
for(int j=0; j<m; j++) bruh[j] = 0;
for(int j=0; j<m; j++) if(answer[i][j] >= 0) bruh[answer[i][j]] = 1;
nxt = 0;
for(int j=0; j<m; j++) {
if(answer[i][j] == -2) {
while(bruh[nxt]) nxt++;
bruh[nxt] = 1;
answer[i][j] = nxt;
}
}
}
allocate_tickets(answer);
return dp[n][n*k/2];
}
# | 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... |