#include <bits/stdc++.h>
using namespace std;
#define ll long long
constexpr int MAXN = 1e5 + 5;
ll sum_tutto(int N, int M, vector<int> X, vector<int> Y, vector<int> W) {
ll sum = 0;
for (auto x : W) sum += x;
return sum;
}
ll res_minore_di_due(int N, int M, vector<int> X, vector<int> Y, vector<int> W) {
if (N == 2) {
// massimo tra 0 e 1
ll one = 0;
ll zero = 0;
for (int i = 0; i < M; i ++) {
if (X[i] == 0) zero += W[i];
else one += W[i];
}
return max(one, zero);
}
// altrimenti piazza una riga in 2 e poi prendi prefisso maggiore piazzando in 1
ll sum = 0;
for (int i = 0; i < M; i ++) {
if (X[i] == 1) sum += W[i];
}
vector<vector<ll>> pos(2, vector<ll>(N + 5, 0));
for (int i = 0; i < M; i ++) {
pos[X[i]][Y[i]] += W[i];
}
ll best_res = sum;
ll sum_zero = 0;
ll sum_uno = 0;
for (int i = 0; i < N + 5; i ++) {
sum_zero += pos[0][i];
sum_uno += pos[1][i];
best_res = max(best_res, sum - sum_uno + sum_zero);
}
return best_res;
}
ll res_y_zero(int N, int M, vector<int> X, vector<int> Y, vector<int> W) {
vector<vector<ll>> dp(2, vector<ll>(N + 5)); // posso prendere a sx o no, posizione
vector<ll> grid(N + 5);
for (int i = 0; i < M; i ++) grid[X[i]] = W[i];
for (int i = N; i >= 0; i --) {
dp[0][i] = dp[1][i + 1];
dp[0][i] = max(dp[0][i], dp[0][i + 1]);
dp[0][i] = max(dp[0][i], dp[0][i + 2] + grid[i + 1]);
dp[0][i] = max(dp[0][i], dp[1][i + 3] + grid[i + 1]);
if (i != 0) {
dp[1][i] = dp[1][i + 1];
dp[1][i] = max(dp[1][i], dp[0][i + 1] + grid[i - 1]);
dp[1][i] = max(dp[1][i], grid[i - 1] + dp[0][i + 2] + grid[i + 1]);
dp[1][i] = max(dp[1][i], grid[i - 1] + dp[1][i + 3] + grid[i + 1]);
}
}
ll best_res = 0;
for (int i = 0; i <= N; i ++) {
best_res = max(best_res, dp[0][i]);
best_res = max(best_res, dp[1][i]);
}
return best_res;
}
ll max_weights(int N, int M, vector<int> X, vector<int> Y, vector<int> W) {
bool all_even = 1;
for (auto x : X) if (x % 2) all_even = 0;
if (all_even) return sum_tutto(N, M, X, Y, W);
bool minore_di_due = 1;
for (auto x : X) if (x >= 2) minore_di_due = 0;
if (minore_di_due) return res_minore_di_due(N, M, X, Y, W);
bool y_zero = 1;
for (auto y : Y) if (y >= 0) minore_di_due = 0;
return res_y_zero(N, M, X, Y, W);
}
Compilation message
fish.cpp: In function 'long long int max_weights(int, int, std::vector<int>, std::vector<int>, std::vector<int>)':
fish.cpp:90:10: warning: unused variable 'y_zero' [-Wunused-variable]
90 | bool y_zero = 1;
| ^~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
20 ms |
4432 KB |
Output is correct |
2 |
Correct |
21 ms |
5564 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
58 ms |
17112 KB |
Output is correct |
6 |
Correct |
62 ms |
17488 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
32 ms |
11028 KB |
Output is correct |
3 |
Correct |
43 ms |
13132 KB |
Output is correct |
4 |
Correct |
18 ms |
4444 KB |
Output is correct |
5 |
Correct |
25 ms |
5664 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
16 ms |
6744 KB |
Output is correct |
13 |
Correct |
20 ms |
7964 KB |
Output is correct |
14 |
Correct |
17 ms |
6636 KB |
Output is correct |
15 |
Correct |
19 ms |
7356 KB |
Output is correct |
16 |
Correct |
18 ms |
6636 KB |
Output is correct |
17 |
Correct |
20 ms |
7372 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
2 ms |
2652 KB |
Output is correct |
3 |
Correct |
12 ms |
5276 KB |
Output is correct |
4 |
Correct |
10 ms |
4576 KB |
Output is correct |
5 |
Incorrect |
19 ms |
7772 KB |
1st lines differ - on the 1st token, expected: '1673106170551', found: '1673122841934' |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
1st lines differ - on the 1st token, expected: '3', found: '2' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
1st lines differ - on the 1st token, expected: '3', found: '2' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
1st lines differ - on the 1st token, expected: '3', found: '2' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
2 ms |
2652 KB |
Output is correct |
3 |
Correct |
12 ms |
5276 KB |
Output is correct |
4 |
Correct |
10 ms |
4576 KB |
Output is correct |
5 |
Incorrect |
19 ms |
7772 KB |
1st lines differ - on the 1st token, expected: '1673106170551', found: '1673122841934' |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
20 ms |
4432 KB |
Output is correct |
2 |
Correct |
21 ms |
5564 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
58 ms |
17112 KB |
Output is correct |
6 |
Correct |
62 ms |
17488 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
32 ms |
11028 KB |
Output is correct |
9 |
Correct |
43 ms |
13132 KB |
Output is correct |
10 |
Correct |
18 ms |
4444 KB |
Output is correct |
11 |
Correct |
25 ms |
5664 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
16 ms |
6744 KB |
Output is correct |
19 |
Correct |
20 ms |
7964 KB |
Output is correct |
20 |
Correct |
17 ms |
6636 KB |
Output is correct |
21 |
Correct |
19 ms |
7356 KB |
Output is correct |
22 |
Correct |
18 ms |
6636 KB |
Output is correct |
23 |
Correct |
20 ms |
7372 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
2 ms |
2652 KB |
Output is correct |
26 |
Correct |
12 ms |
5276 KB |
Output is correct |
27 |
Correct |
10 ms |
4576 KB |
Output is correct |
28 |
Incorrect |
19 ms |
7772 KB |
1st lines differ - on the 1st token, expected: '1673106170551', found: '1673122841934' |
29 |
Halted |
0 ms |
0 KB |
- |