이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "fish.h"
#include <bits/stdc++.h>
#define ll long long
#define f frist
#define s second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pb push_back
#define epb emplace_back
#define ull unsigned ll;
#include <vector>
using namespace std;
const int NMAX = 1e6 + 1;
map<pii, ll> val;
vector <vector <ll> > dp(NMAX);
vector <vector <ll> > DP(NMAX);
map<pii, int> ind;
long long max_weights(int N, int M, std::vector<int> X, std::vector<int> Y,std::vector<int> W) {
int n = N, m = M;
vector <vector <int> > vec(n + 2);
for(int i = 0; i < M; i++){
vec[X[i] + 1].pb(Y[i] + 1);
val[{X[i] + 1,Y[i] + 1}] = W[i];
}
for(int i = 0; i <= n + 1; i++){
if(val[{i, 0}] == 0) vec[i].pb(0);
if(val[{i, n}] == 0) vec[i].pb(n);
//sort(vec[i].begin(), vec[i].end());
}
for(int i = 0; i < M; i++){
if(Y[i] < n - 2){
ll v = val[{X[i], Y[i] + 2}];
if(v == 0) vec[X[i]].pb(Y[i] + 2);
}
if(Y[i] > 0){
ll v = val[{X[i], Y[i]}];
if(v == 0) vec[X[i]].pb(Y[i]);
}
}
for(int i = 0; i <= n + 1; i++){
sort(vec[i].begin(), vec[i].end());
dp[i].resize(vec[i].size());
DP[i].resize(vec[i].size());
}
for(int i= 0; i <= n + 1; i++){
for(int j = 0; j < vec[i].size(); j++){
int x = vec[i][j];
ind[{i, x}] = j;
}
}
for(int i = 1; i <= n + 1; i++){
if(i > 1){
ll last = -1;
for(int j = vec[i].size() - 1; j >= 0; j--){
ll vv = val[{i, vec[i][j]}];
int ind1 = ind[{i - 1, vec[i][j] + 1}];
if(last == -1){
dp[i][j] = max(dp[i - 2][0], DP[i - 2].back()) + vv;
}
else{
dp[i][j] = max(dp[i - 1][ind1], dp[i][j + 1]) + vv;
}
last = dp[i][j];
}
}
for(int j = 0; j < vec[i].size(); j++){
ll vv = val[{i, vec[i][j]}];
int ind1 = ind[{i - 1, vec[i][j] - 1}];
if(j == 0){
DP[i][j] = dp[i - 1][0] + vv;
}
else{
DP[i][j] = max(DP[i][j - 1] , DP[i - 1][ind1]) + vv;
}
}
}
ll ans = 0;
for(int i= 0; i <= n + 1; i++) ans = max(dp[i][0], ans);
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:50:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
50 | for(int j = 0; j < vec[i].size(); j++){
| ~~^~~~~~~~~~~~~~~
fish.cpp:70:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
70 | for(int j = 0; j < vec[i].size(); j++){
| ~~^~~~~~~~~~~~~~~
fish.cpp:23:16: warning: unused variable 'm' [-Wunused-variable]
23 | int n = N, m = M;
| ^
# | 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... |