이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "fish.h"
#include <bits/stdc++.h>
using namespace std;
long long fish[100100][2], dp[100100][2], dp2[100100][2], dpm[100100][2], dpm2[100100][2];
long long max_weights(int N, int M, vector<int> X, vector<int> Y, vector<int> W) {
for(int i = 0; i < M; i++)
fish[X[i]][Y[i]+1]=W[i];
for(int i = 0; i < N; i++)
for(int j = 1; j < N; j++)
fish[i][j]+=fish[i][j-1];
for(int l = 1; l < N; l++) {
for(int i = 0; i <= N; i++) {
for(int j = 0; j <= N; j++) {
if(i<=j) {
dp[i][j] = dpm[j][N]+fish[l][j]-fish[l][i];
} else {
dp[i][j] = dpm[j][j]+fish[l-1][i]-fish[l-1][j];
dp[i][j]=max(dp[i][j],dpm2[j][i]);
for(int k = j; k < i; k++)
dp[i][j] = max(dp[i][j], dp2[j][k]+fish[l-1][i]-fish[l-1][k]);
}
}
}
swap(dp, dp2);
memset(dp, 0, sizeof dp);
memcpy(dpm, dp2, sizeof dp2);
memcpy(dpm2, dp2, sizeof dp2);
for(int i = 0; i <= N; i++)
for(int j = 1; j <= N; j++)
dpm[i][j] = max(dpm[i][j-1], dpm[i][j]);
for(int i = 0; i <= N; i++)
for(int j = N; j--;)
dpm2[i][j] = max(dpm2[i][j+1], dpm2[i][j]);
}
long long ans = 0;
for(int i = 0; i <= N; i++)
for(int j = 0; j <= N; j++)
ans = max(ans, dp2[i][j]);
return ans;
}
컴파일 시 표준 에러 (stderr) 메시지
fish.cpp: In function 'long long int max_weights(int, int, std::vector<int>, std::vector<int>, std::vector<int>)':
fish.cpp:16:40: warning: array subscript 2 is above array bounds of 'long long int [2]' [-Warray-bounds]
16 | dp[i][j] = dpm[j][N]+fish[l][j]-fish[l][i];
| ~~~~~~~~^
# | 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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |