# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
627698 |
2022-08-12T19:05:51 Z |
tutis |
Catfish Farm (IOI22_fish) |
C++17 |
|
1000 ms |
2097152 KB |
#include "fish.h"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
long long max_weights(int N, int M, std::vector<int> X, std::vector<int> Y,
std::vector<int> W) {
vector<pair<int, ll>>P[N];
for (int i = 0; i < M; i++)
P[X[i]].push_back({Y[i], W[i]});
for (int i = 0; i < N; i++)
sort(P[i].begin(), P[i].end());
for (int i = 0; i < N; i++)
{
P[i].push_back({N, 0});
for (int j = 1; j < (int)P[i].size(); j++)
P[i][j].second += P[i][j - 1].second;
}
int ret = 0;
ll dp[N];
ll u[N][N];
ll d[N][N];
ll u1[N][N];
ll d1[N][N];
auto get = [&](int x, int y)->ll
{
if (x < 0 || x >= N)
return 0;
auto it = lower_bound(P[x].begin(), P[x].end(), make_pair(y + 1, -1ll));
if (it == P[x].begin())
return 0;
it--;
return it->second;
};
for (int x = 0; x < N; x++)
{
dp[x] = 0;
for (int y = 0; y < N; y++)
{
u[x][y] = d[x][y] = 0;
u1[x][y] = u[x][y] - get(x, y);
d1[x][y] = d[x][y] + get(x + 1, y);
}
if (x == 0)
continue;
ll mx = -1e18;
for (int y = 0; y < N; y++)
{
u[x][y] = dp[x - 1];
u[x][y] = max(u[x][y], get(x - 1, y) + (x - 2 >= 0 ? dp[x - 2] : 0ll));
u[x][y] -= get(x - 1, y);
mx = max(mx, u1[x - 1][y]);
u[x][y] = max(u[x][y], mx);
u[x][y] += get(x - 1, y);
}
for (int y = 0; y < N; y++)
u1[x][y] = u[x][y] - get(x, y);
d[x][N - 1] = u[x][N - 1];
mx = -1e18;
for (int y = N - 1; y >= 0; y--)
{
d[x][y] += get(x, y);
mx = max(mx, d1[x - 1][y]);
d[x][y] = max(d[x][y], mx);
d[x][y] -= get(x, y);
}
for (int y = N - 1; y >= 0; y--)
d1[x][y] = d[x][y] + get(x + 1, y);
dp[x] = dp[x - 1];
dp[x] = max(dp[x], get(x, N - 1) + u[x - 1][N - 1]);
dp[x] = max(dp[x], u[x][N - 1]);
for (int y = 0; y < N; y++)
{
dp[x] = max(dp[x], d1[x - 1][y]);
dp[x] = max(dp[x], d[x][y]);
}
}
return dp[N - 1];
}
Compilation message
fish.cpp: In function 'long long int max_weights(int, int, std::vector<int>, std::vector<int>, std::vector<int>)':
fish.cpp:19:9: warning: unused variable 'ret' [-Wunused-variable]
19 | int ret = 0;
| ^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
769 ms |
2097152 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
256 KB |
Output is correct |
2 |
Runtime error |
812 ms |
2097152 KB |
Execution killed with signal 9 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
749 ms |
2097152 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
296 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
2 ms |
980 KB |
Output is correct |
10 |
Correct |
8 ms |
3196 KB |
Output is correct |
11 |
Correct |
2 ms |
980 KB |
Output is correct |
12 |
Correct |
6 ms |
3156 KB |
Output is correct |
13 |
Correct |
1 ms |
468 KB |
Output is correct |
14 |
Correct |
6 ms |
3156 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
296 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
2 ms |
980 KB |
Output is correct |
10 |
Correct |
8 ms |
3196 KB |
Output is correct |
11 |
Correct |
2 ms |
980 KB |
Output is correct |
12 |
Correct |
6 ms |
3156 KB |
Output is correct |
13 |
Correct |
1 ms |
468 KB |
Output is correct |
14 |
Correct |
6 ms |
3156 KB |
Output is correct |
15 |
Correct |
7 ms |
3148 KB |
Output is correct |
16 |
Correct |
2 ms |
468 KB |
Output is correct |
17 |
Correct |
39 ms |
5076 KB |
Output is correct |
18 |
Correct |
35 ms |
5716 KB |
Output is correct |
19 |
Correct |
29 ms |
5460 KB |
Output is correct |
20 |
Correct |
30 ms |
5444 KB |
Output is correct |
21 |
Correct |
29 ms |
5448 KB |
Output is correct |
22 |
Correct |
72 ms |
7884 KB |
Output is correct |
23 |
Correct |
14 ms |
3540 KB |
Output is correct |
24 |
Correct |
32 ms |
4528 KB |
Output is correct |
25 |
Correct |
6 ms |
3156 KB |
Output is correct |
26 |
Correct |
14 ms |
3540 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
296 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
2 ms |
980 KB |
Output is correct |
10 |
Correct |
8 ms |
3196 KB |
Output is correct |
11 |
Correct |
2 ms |
980 KB |
Output is correct |
12 |
Correct |
6 ms |
3156 KB |
Output is correct |
13 |
Correct |
1 ms |
468 KB |
Output is correct |
14 |
Correct |
6 ms |
3156 KB |
Output is correct |
15 |
Correct |
7 ms |
3148 KB |
Output is correct |
16 |
Correct |
2 ms |
468 KB |
Output is correct |
17 |
Correct |
39 ms |
5076 KB |
Output is correct |
18 |
Correct |
35 ms |
5716 KB |
Output is correct |
19 |
Correct |
29 ms |
5460 KB |
Output is correct |
20 |
Correct |
30 ms |
5444 KB |
Output is correct |
21 |
Correct |
29 ms |
5448 KB |
Output is correct |
22 |
Correct |
72 ms |
7884 KB |
Output is correct |
23 |
Correct |
14 ms |
3540 KB |
Output is correct |
24 |
Correct |
32 ms |
4528 KB |
Output is correct |
25 |
Correct |
6 ms |
3156 KB |
Output is correct |
26 |
Correct |
14 ms |
3540 KB |
Output is correct |
27 |
Correct |
430 ms |
282500 KB |
Output is correct |
28 |
Correct |
225 ms |
30960 KB |
Output is correct |
29 |
Correct |
663 ms |
298536 KB |
Output is correct |
30 |
Execution timed out |
1088 ms |
297928 KB |
Time limit exceeded |
31 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
749 ms |
2097152 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
769 ms |
2097152 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |