#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;
long long max_weights(int N, int M, vector<int> X, vector<int> Y, vector<int> W) {
int block1 = 0;
for (auto c : X) block1 += (c & 1 ^ 1);
if (block1 == M)
return accumulate(all(W), 0ll);
long long dp[N][2];
for (int i = 0; i < N; i++)
for (int j : {0, 1})
dp[i][j] = 0;
long long has[N + 1];
for (int i = 0; i <= N; i++)
has[i] = 0;
for (int i = 0; i < M; i++)
has[X[i]] = W[i];
dp[0][1] = has[0];
for (int i = 1; i < N; i++) {
long long over2 = -1;
if (i > 1) over2 = max(over2, dp[i - 2][0] + has[i - 1]);
if (i > 1) over2 = max(over2, dp[i - 2][1]);
dp[i][1] = has[i + 1] + max(over2, dp[i - 1][1] - has[i]);
dp[i][0] = max(dp[i-1][1], dp[i-1][0]);
}
return max(dp[N - 1][0], dp[N - 1][1]);
}
//main() {
// int N = 10, M = 4;
// vector <int> X = {0, 5, 7, 4};
// vector <int> Y = {0, 0, 0, 0};
// vector <int> W = {10, 5, 3, 6};
// cout << max_weights(N, M, X, Y, W) << '\n';
//}
Compilation message
fish.cpp: In function 'long long int max_weights(int, int, std::vector<int>, std::vector<int>, std::vector<int>)':
fish.cpp:9:35: warning: suggest parentheses around arithmetic in operand of '^' [-Wparentheses]
9 | for (auto c : X) block1 += (c & 1 ^ 1);
| ~~^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
21 ms |
2156 KB |
Output is correct |
2 |
Correct |
26 ms |
2644 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
86 ms |
7268 KB |
Output is correct |
6 |
Correct |
111 ms |
7276 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
1st lines differ - on the 1st token, expected: '2', found: '1' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
2 ms |
2644 KB |
Output is correct |
3 |
Incorrect |
15 ms |
3632 KB |
1st lines differ - on the 1st token, expected: '21261825233649', found: '21261347173731' |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
1st lines differ - on the 1st token, expected: '3', found: '2' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
1st lines differ - on the 1st token, expected: '3', found: '2' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
1st lines differ - on the 1st token, expected: '3', found: '2' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
2 ms |
2644 KB |
Output is correct |
3 |
Incorrect |
15 ms |
3632 KB |
1st lines differ - on the 1st token, expected: '21261825233649', found: '21261347173731' |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
21 ms |
2156 KB |
Output is correct |
2 |
Correct |
26 ms |
2644 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
86 ms |
7268 KB |
Output is correct |
6 |
Correct |
111 ms |
7276 KB |
Output is correct |
7 |
Incorrect |
0 ms |
212 KB |
1st lines differ - on the 1st token, expected: '2', found: '1' |
8 |
Halted |
0 ms |
0 KB |
- |