# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1075114 |
2024-08-25T18:37:45 Z |
Zicrus |
Catfish Farm (IOI22_fish) |
C++17 |
|
1000 ms |
2097152 KB |
#include <bits/stdc++.h>
#include "fish.h"
using namespace std;
typedef long long ll;
int n, m;
vector<int> x, y, w;
vector<vector<pair<int, int>>> f; // y, w
vector<vector<int>> relH;
ll sum(int i, int j) {
ll res = 0;
for (int k = 0; k < f[i].size(); k++) {
if (f[i][k].first < j) res += f[i][k].second;
}
return res;
}
ll max_weights(int N, int M, vector<int> X, vector<int> Y, vector<int> W) {
n = N; m = M; x = X; y = Y; w = W;
f = vector<vector<pair<int, int>>>(n);
relH = vector<vector<int>>(n);
for (int i = 0; i < m; i++) {
f[x[i]].push_back({y[i], w[i]});
if (x[i] > 0) relH[x[i]-1].push_back(y[i]+1);
if (x[i] < n-1) relH[x[i]+1].push_back(y[i]+1);
}
for (int i = 0; i < n; i++) {
relH[i].push_back(0);
sort(f[i].begin(), f[i].end());
sort(relH[i].begin(), relH[i].end());
}
vector<vector<vector<ll>>> dp(n);
for (int j = 0; j < relH[0].size(); j++) {
dp[0].push_back(vector<ll>(1));
}
for (int i = 1; i < n; i++) {
dp[i] = vector<vector<ll>>(relH[i].size());
for (int j = 0; j < relH[i].size(); j++) {
dp[i][j] = vector<ll>(relH[i-1].size());
}
}
for (int i = 1; i < n; i++) {
for (int j = 0; j < relH[i].size(); j++) {
for (int j1 = 0; j1 < relH[i-1].size(); j1++) {
for (int k = 0; k < (i < 2 ? 1 : relH[i-2].size()); k++) {
ll val = dp[i-1][j1][k];
if (relH[i-1][j1] > relH[i][j]) val += sum(i, relH[i-1][j1]) - sum(i, relH[i][j]);
if (relH[i][j] > max(relH[i-1][j1], i < 2 ? 0 : relH[i-2][k])) val += sum(i-1, relH[i][j]) - sum(i-1, max(relH[i-1][j1], i < 2 ? 0 : relH[i-2][k]));
dp[i][j][j1] = max(dp[i][j][j1], val);
}
}
}
}
ll res = 0;
for (int j = 0; j < relH[n-1].size(); j++) {
for (int j1 = 0; j1 < relH[n-2].size(); j1++) {
res = max(res, dp[n-1][j][j1]);
}
}
return res;
}
#ifdef TEST
#include "grader.cpp"
#endif
Compilation message
fish.cpp: In function 'll sum(int, int)':
fish.cpp:14:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
14 | for (int k = 0; k < f[i].size(); k++) {
| ~~^~~~~~~~~~~~~
fish.cpp: In function 'll max_weights(int, int, std::vector<int>, std::vector<int>, std::vector<int>)':
fish.cpp:36:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
36 | for (int j = 0; j < relH[0].size(); j++) {
| ~~^~~~~~~~~~~~~~~~
fish.cpp:41:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
41 | for (int j = 0; j < relH[i].size(); j++) {
| ~~^~~~~~~~~~~~~~~~
fish.cpp:46:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
46 | for (int j = 0; j < relH[i].size(); j++) {
| ~~^~~~~~~~~~~~~~~~
fish.cpp:47:33: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
47 | for (int j1 = 0; j1 < relH[i-1].size(); j1++) {
| ~~~^~~~~~~~~~~~~~~~~~
fish.cpp:48:35: warning: comparison of integer expressions of different signedness: 'int' and 'long unsigned int' [-Wsign-compare]
48 | for (int k = 0; k < (i < 2 ? 1 : relH[i-2].size()); k++) {
| ~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
fish.cpp:59:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
59 | for (int j = 0; j < relH[n-1].size(); j++) {
| ~~^~~~~~~~~~~~~~~~~~
fish.cpp:60:29: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
60 | for (int j1 = 0; j1 < relH[n-2].size(); j1++) {
| ~~~^~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1014 ms |
25032 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Runtime error |
851 ms |
2097152 KB |
Execution killed with signal 9 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
16732 KB |
Output is correct |
2 |
Correct |
17 ms |
16820 KB |
Output is correct |
3 |
Correct |
53 ms |
25664 KB |
Output is correct |
4 |
Correct |
44 ms |
23692 KB |
Output is correct |
5 |
Correct |
93 ms |
36044 KB |
Output is correct |
6 |
Correct |
73 ms |
35240 KB |
Output is correct |
7 |
Correct |
77 ms |
35924 KB |
Output is correct |
8 |
Correct |
86 ms |
35916 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
356 KB |
Output is correct |
9 |
Correct |
1 ms |
604 KB |
Output is correct |
10 |
Correct |
16 ms |
1500 KB |
Output is correct |
11 |
Correct |
3 ms |
600 KB |
Output is correct |
12 |
Correct |
3 ms |
608 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
2 ms |
604 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
356 KB |
Output is correct |
9 |
Correct |
1 ms |
604 KB |
Output is correct |
10 |
Correct |
16 ms |
1500 KB |
Output is correct |
11 |
Correct |
3 ms |
600 KB |
Output is correct |
12 |
Correct |
3 ms |
608 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
2 ms |
604 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Execution timed out |
1068 ms |
4188 KB |
Time limit exceeded |
17 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
356 KB |
Output is correct |
9 |
Correct |
1 ms |
604 KB |
Output is correct |
10 |
Correct |
16 ms |
1500 KB |
Output is correct |
11 |
Correct |
3 ms |
600 KB |
Output is correct |
12 |
Correct |
3 ms |
608 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
2 ms |
604 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Execution timed out |
1068 ms |
4188 KB |
Time limit exceeded |
17 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
16732 KB |
Output is correct |
2 |
Correct |
17 ms |
16820 KB |
Output is correct |
3 |
Correct |
53 ms |
25664 KB |
Output is correct |
4 |
Correct |
44 ms |
23692 KB |
Output is correct |
5 |
Correct |
93 ms |
36044 KB |
Output is correct |
6 |
Correct |
73 ms |
35240 KB |
Output is correct |
7 |
Correct |
77 ms |
35924 KB |
Output is correct |
8 |
Correct |
86 ms |
35916 KB |
Output is correct |
9 |
Correct |
86 ms |
35752 KB |
Output is correct |
10 |
Correct |
93 ms |
31824 KB |
Output is correct |
11 |
Correct |
195 ms |
63056 KB |
Output is correct |
12 |
Correct |
0 ms |
344 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 |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
18 ms |
16732 KB |
Output is correct |
19 |
Correct |
17 ms |
16728 KB |
Output is correct |
20 |
Correct |
18 ms |
16732 KB |
Output is correct |
21 |
Correct |
17 ms |
16732 KB |
Output is correct |
22 |
Correct |
94 ms |
37460 KB |
Output is correct |
23 |
Correct |
200 ms |
63196 KB |
Output is correct |
24 |
Correct |
203 ms |
63824 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1014 ms |
25032 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |