#ifndef FISH_CPP_INCLUDED
#define FISH_CPP_INCLUDED
#include "fish.h"
#include <vector>
#include <cstring>
#include <cassert>
#include <iostream>
#include <algorithm>
typedef long long ll;
/**
dp[i][j] =def= nr minim de operatii ca sa fac primele i
**/
bool sub1(std::vector<int> v) {
for (const auto &x : v) {
if (x & 1) {
return false;
}
}
return true;
}
long long max_weights(int n, int m, std::vector<int> x, std::vector<int> y,
std::vector<int> w) {
if (sub1(x)) {
ll s = 0;
for (const auto &v : w) {
s += v;
}
return s;
}
n++;
ll cnt[n + 1][n + 1];
memset(cnt, 0, sizeof(cnt));
for (int i = 0; i < m; i++) {
x[i]++, y[i]++;
std::swap(x[i], y[i]);
cnt[y[i]][x[i]] += w[i];
}
for (int j = 1; j <= n; j++) {
for (int i = 1; i <= n; i++) {
cnt[j][i] += cnt[j][i - 1];
}
}
ll dp[n + 1][n + 1];
memset(dp, 0, sizeof(dp));
for (int i = 2; i <= n; i++) {
for (int j = 0; j <= (i == n? 0 : n); j++) {
for (int k = 0; k <= (i == 2? 0 : n); k++) {
dp[i][j] = std::max(dp[i][j], dp[i - 2][k] + cnt[i - 1][std::max(j, k)]);
}
for (int k = 0; k <= n; k++) {
dp[i][j] = std::max(dp[i][j], dp[i - 1][k] + cnt[i][k] - cnt[i][j]);
}
}
}
// for (int j = n; j >= 0; j--) {
// for (int i = 1; i <= n; i++) {
// std::cout << dp[i][j] << ' ';
// }
// std::cout << '\n';
// }
return dp[n][0];
return 0;
}
#endif // FISH_CPP_INCLUDED
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
18 ms |
3920 KB |
Output is correct |
2 |
Correct |
22 ms |
4800 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
68 ms |
14932 KB |
Output is correct |
6 |
Correct |
78 ms |
15336 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
1st lines differ - on the 1st token, expected: '2', found: '1' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Execution timed out |
1191 ms |
2097152 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
600 KB |
1st lines differ - on the 1st token, expected: '3', found: '2' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
600 KB |
1st lines differ - on the 1st token, expected: '3', found: '2' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
600 KB |
1st lines differ - on the 1st token, expected: '3', found: '2' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Execution timed out |
1191 ms |
2097152 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
18 ms |
3920 KB |
Output is correct |
2 |
Correct |
22 ms |
4800 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
68 ms |
14932 KB |
Output is correct |
6 |
Correct |
78 ms |
15336 KB |
Output is correct |
7 |
Incorrect |
0 ms |
348 KB |
1st lines differ - on the 1st token, expected: '2', found: '1' |
8 |
Halted |
0 ms |
0 KB |
- |