#include "fish.h"
#include <algorithm>
#include <bitset>
#include <cstdint>
#include <cstring>
#include <iostream>
#include <limits.h>
#include <math.h>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define int long long
#define loop(X, N) for(int X = 0; X < (N); X++)
#define all(V) V.begin(), V.end()
#define rall(V) V.rbegin(), V.rend()
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<vector<ii>> vvii;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
vvii fishes;
int weightSum(int x, int y1, int y2) {
if (x >= fishes.size())
return 0;
int res = 0;
for (auto [y, w] : fishes[x]) {
if (y1 <= y && y <= y2)
res += w;
}
return res;
}
long long max_weights(signed N, signed M, vector<signed> X, std::vector<signed> Y, std::vector<signed> W) {
fishes = vvii(N);
loop(i, M) {
fishes[X[i]].push_back({Y[i], W[i]});
}
vector<map<int, int>> dp(N);
loop(x, N) {
auto& col = fishes[x];
sort(all(col), greater<ii>{});
if (x == 0) {
for (auto [y, w] : col) {
dp[0][y - 1] = weightSum(1, 0, y - 1);
}
dp[0][0] = 0;
continue;
}
for (auto [y, w] : fishes[x - 1]) {
int bestScore = 0;
for (auto [prevY, prevScore] : dp[x - 1]) {
int score = prevScore
- weightSum(x, 0, min(prevY, y))
+ weightSum(x + 1, 0, y)
+ weightSum(x - 1, prevY + 1, y);
bestScore = max(bestScore, score);
}
dp[x][y] = bestScore;
}
int bestScore = 0;
for (auto [prevY, prevScore] : dp[x - 1]) {
int score = prevScore;
bestScore = max(bestScore, score);
}
dp[x][0] = max(dp[x][0], bestScore);
}
int res = 0;
for (auto [y, score] : dp.back()) {
res = max(res, score);
}
return res;
}
Compilation message
fish.cpp: In function 'long long int weightSum(long long int, long long int, long long int)':
fish.cpp:35:11: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::vector<std::pair<long long int, long long int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
35 | if (x >= fishes.size())
| ~~^~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1066 ms |
16328 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Execution timed out |
1043 ms |
16756 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
13656 KB |
Output is correct |
2 |
Incorrect |
9 ms |
13660 KB |
1st lines differ - on the 1st token, expected: '882019', found: '0' |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Incorrect |
0 ms |
348 KB |
1st lines differ - on the 1st token, expected: '4044', found: '2022' |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Incorrect |
0 ms |
348 KB |
1st lines differ - on the 1st token, expected: '4044', found: '2022' |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Incorrect |
0 ms |
348 KB |
1st lines differ - on the 1st token, expected: '4044', found: '2022' |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
13656 KB |
Output is correct |
2 |
Incorrect |
9 ms |
13660 KB |
1st lines differ - on the 1st token, expected: '882019', found: '0' |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1066 ms |
16328 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |