# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
659603 |
2022-11-18T17:49:38 Z |
peijar |
Catfish Farm (IOI22_fish) |
C++17 |
|
1000 ms |
27988 KB |
#include "fish.h"
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int INF = 1e18;
int max_weights(signed N, signed M, vector<signed> X, vector<signed> Y,
vector<signed> W) {
vector<vector<pair<int, int>>> onCol(N);
vector<vector<int>> prefSum(N);
for (int i = 0; i < M; ++i)
onCol[X[i]].emplace_back(Y[i] + 1, W[i]);
for (int i = 0; i < N; ++i) {
sort(onCol[i].begin(), onCol[i].end());
prefSum[i].resize(onCol[i].size() + 1);
for (int j = 0; j < (int)onCol[i].size(); ++j)
prefSum[i][j + 1] = prefSum[i][j] + onCol[i][j].second;
}
vector<vector<int>> interesting(N);
for (int i = 0; i < N; ++i) {
interesting[i].push_back(0);
for (auto [y, w] : onCol[i])
interesting[i].push_back(y);
if (i)
for (auto [y, w] : onCol[i - 1])
interesting[i].push_back(y);
if (i + 1 < N)
for (auto [y, w] : onCol[i + 1])
interesting[i].push_back(y);
interesting[i].push_back(N);
sort(interesting[i].begin(), interesting[i].end());
interesting[i].resize(unique(interesting[i].begin(), interesting[i].end()) -
interesting[i].begin());
}
array<vector<pair<int, int>>, 2> oldDp, suffixMax;
for (int i = 0; i < 2; ++i)
oldDp[i] = suffixMax[i] = {{0, 0}};
auto eval = [&](int side, int h) {
auto it = upper_bound(oldDp[side].begin(), oldDp[side].end(), pair(h, INF));
assert(it != oldDp[side].begin());
--it;
return it->second;
};
auto getSum = [&](int i, int h1, int h2) -> int {
int lo = upper_bound(onCol[i].begin(), onCol[i].end(), pair(h1, INF)) -
onCol[i].begin();
int up = upper_bound(onCol[i].begin(), onCol[i].end(), pair(h2, INF)) -
onCol[i].begin();
return prefSum[i][up] - prefSum[i][lo];
};
int sol = 0;
for (int i = 1; i < N; ++i) {
int nbInteressants = interesting[i].size();
vector<pair<int, int>> dp0, dp1;
for (int iHauteur = 0; iHauteur < nbInteressants; ++iHauteur) {
int h = interesting[i][iHauteur];
// 1
int v1 = 0;
int v0 = 0;
for (int jHauteur = 0; jHauteur < (int)interesting[i - 1].size();
++jHauteur) {
int oldH = interesting[i - 1][jHauteur];
if (oldH > h)
v1 = max(v1, getSum(i, h, oldH) + eval(1, oldH));
if (oldH >= h)
// suffix max -> ez
v0 = max(v0, eval(1, oldH));
else
v0 = max(v0, getSum(i - 1, oldH, h) + eval(0, oldH));
}
v1 = max(v1, v0);
sol = max(sol, v1);
dp0.emplace_back(h, v0);
dp1.emplace_back(h, v1);
// cout << i << ' ' << h << ' ' << v0 << ' ' << v1 << endl;
}
oldDp[0] = move(dp0);
oldDp[1] = move(dp1);
suffixMax[0] = oldDp[0];
suffixMax[1] = oldDp[1];
for (int h = nbInteressants - 2; h >= 0; --h)
for (int side = 0; side < 2; ++side)
suffixMax[side][h].second =
max(suffixMax[side][h].second, suffixMax[side][h + 1].second);
}
return sol;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1090 ms |
17608 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Execution timed out |
1093 ms |
23140 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
41 ms |
13524 KB |
Output is correct |
2 |
Correct |
35 ms |
13552 KB |
Output is correct |
3 |
Correct |
70 ms |
17440 KB |
Output is correct |
4 |
Correct |
64 ms |
17228 KB |
Output is correct |
5 |
Correct |
145 ms |
23756 KB |
Output is correct |
6 |
Correct |
104 ms |
23672 KB |
Output is correct |
7 |
Correct |
109 ms |
23764 KB |
Output is correct |
8 |
Correct |
119 ms |
23780 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
276 KB |
Output is correct |
5 |
Correct |
0 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 |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
3 ms |
468 KB |
Output is correct |
11 |
Correct |
2 ms |
340 KB |
Output is correct |
12 |
Correct |
2 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
276 KB |
Output is correct |
5 |
Correct |
0 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 |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
3 ms |
468 KB |
Output is correct |
11 |
Correct |
2 ms |
340 KB |
Output is correct |
12 |
Correct |
2 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
19 ms |
508 KB |
Output is correct |
17 |
Execution timed out |
1080 ms |
4032 KB |
Time limit exceeded |
18 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
276 KB |
Output is correct |
5 |
Correct |
0 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 |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
3 ms |
468 KB |
Output is correct |
11 |
Correct |
2 ms |
340 KB |
Output is correct |
12 |
Correct |
2 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
19 ms |
508 KB |
Output is correct |
17 |
Execution timed out |
1080 ms |
4032 KB |
Time limit exceeded |
18 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
41 ms |
13524 KB |
Output is correct |
2 |
Correct |
35 ms |
13552 KB |
Output is correct |
3 |
Correct |
70 ms |
17440 KB |
Output is correct |
4 |
Correct |
64 ms |
17228 KB |
Output is correct |
5 |
Correct |
145 ms |
23756 KB |
Output is correct |
6 |
Correct |
104 ms |
23672 KB |
Output is correct |
7 |
Correct |
109 ms |
23764 KB |
Output is correct |
8 |
Correct |
119 ms |
23780 KB |
Output is correct |
9 |
Correct |
144 ms |
23776 KB |
Output is correct |
10 |
Correct |
77 ms |
14012 KB |
Output is correct |
11 |
Correct |
225 ms |
27872 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
36 ms |
13504 KB |
Output is correct |
19 |
Correct |
38 ms |
13564 KB |
Output is correct |
20 |
Correct |
41 ms |
13560 KB |
Output is correct |
21 |
Correct |
36 ms |
13688 KB |
Output is correct |
22 |
Correct |
177 ms |
21960 KB |
Output is correct |
23 |
Correct |
233 ms |
27988 KB |
Output is correct |
24 |
Correct |
255 ms |
27876 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1090 ms |
17608 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |