이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define pb push_back
const int N = 1e5 + 100;
ll dp[N][15][2], a[N][2], s[N], pref[N][15], dp_pref[N][15], dp_suf[N][15], dp_pref_max[N][15], dp_suf_max[N][15];
long long max_weights(int n, int m, std::vector<int> x, std::vector<int> y, std::vector<int> w){
bool case1 = 1, case2 = 1;
for(int i = 0; i < m; ++i){
if(x[i] % 2) case1 = 0;
if(x[i] > 1) case2 = 0;
}
if(case1){
ll ans = 0;
for(int i = 0; i < m; ++i) ans += w[i];
return ans;
}
if(case2){
ll ans1 = 0, ans2 = 0;
for(int i = 0; i < m; ++i){
if(x[i] == 0) ans1 += w[i];
else ans2 += w[i];
}
if(n == 2)
return max(ans1, ans2);
else{
ll best = 0, sum = 0;
int p = 0;
for(int i = 0; i <= n + 1; ++i) a[i][0] = a[i][1] = s[i] = 0;
for(int i = 0; i < m; i++) if(x[i] == 0) a[y[i]][0] = w[i]; else a[y[i]][1] = w[i];
for(int i = n; i >= 0; --i) s[i] = s[i + 1] + a[i][1];
for(int i = 0; i <= n + 1; ++i){
best = max(best, s[i] + sum);
sum += a[i][0];
}
return best;
}
}
for(int i = 0; i <= n + 5; ++i){
for(int j = 0; j < 15; ++j) pref[i][j] = dp[i][j][0] = dp[i][j][1] = dp_pref[i][j] = dp_suf[i][j] = dp_pref_max[i][j] = 0;
}
for(int i = 0; i < m; ++i) pref[x[i]][y[i] + 1] = w[i];
for(int i = 0; i <= n; ++i){
for(int j = 1; j < 15; ++j) pref[i][j] += pref[i][j - 1];
}
for(int i = 0; i <= n; ++i){
for(int j = 0; j < 10; ++j){
if(i == 0){
dp[i][j][0] = dp[i][j][1] = pref[i + 1][j];
continue;
}
dp[i][j][0] = pref[i + 1][j];
if(i == 1){
dp[i][j][0] += dp_pref[i - 1][j] + pref[i - 1][j];
}else{
dp[i][j][0] += max({dp_pref[i - 1][j] + pref[i - 1][j],
dp_suf[i - 2][0],
dp_pref_max[i - 2][j] + pref[i - 1][j]
});
}
dp[i][j][1] = pref[i + 1][j] - pref[i][j] + dp_suf[i - 1][j];
}
for(int j = 0; j < 10; ++j){
if(j == 0){
dp_pref[i][j] = dp[i][j][0] - pref[i + 1][j] - pref[i][j];
dp_pref_max[i][j] = max(dp[i][j][0], dp[i][j][1]) - pref[i + 1][j];
}
else{
dp_pref[i][j] = max(dp_pref[i][j - 1], dp[i][j][0] - pref[i + 1][j] - pref[i][j]);
dp_pref_max[i][j] = max(dp_pref_max[i][j - 1], max(dp[i][j][0], dp[i][j][1]) - pref[i + 1][j]);
}
}
for(int j = 9; j >= 0; --j){
if(j == 9){
dp_suf[i][j] = max(dp[i][j][0], dp[i][j][1]);
dp_suf_max[i][j] = max(dp[i][j][0], dp[i][j][1]) + pref[i + 1][j];
}
else{
dp_suf[i][j] = max({dp_suf[i][j + 1], dp[i][j][0], dp[i][j][1]});
dp_suf_max[i][j] = max(dp_suf_max[i][j - 1], max(dp[i][j][0], dp[i][j][1]) + pref[i + 1][j]);
}
}
}
return max(dp[n][0][0], dp[n][0][1]);
}
컴파일 시 표준 에러 (stderr) 메시지
fish.cpp: In function 'long long int max_weights(int, int, std::vector<int>, std::vector<int>, std::vector<int>)':
fish.cpp:31:17: warning: unused variable 'p' [-Wunused-variable]
31 | int p = 0;
| ^
# | 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... |