# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1046749 |
2024-08-06T21:31:13 Z |
Trent |
Catfish Farm (IOI22_fish) |
C++17 |
|
1000 ms |
251172 KB |
#include "fish.h"
#include "bits/stdc++.h";
using namespace std;
#define forR(i, x) for(int i = 0; i < (x); ++i)
#define REP(i, a, b) for(int i = (a); i < (b); ++i)
#define all(x) x.begin(), x.end()
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<int> vi;
typedef vector<vi> vvi;
struct pii{int a, b;};
ll INF = 1e16;
ll rSum(int i, vector<pii>& wx, vll& psa) {
int ind = upper_bound(all(wx), i, [](int a, pii b){return a < b.a;}) - wx.begin();
if(ind - 1 == -1) return 0;
return psa[ind-1];
}
long long max_weights(int N, int M, std::vector<int> X, std::vector<int> Y,
std::vector<int> W) {
vector<vector<pii>> wx(N);
forR(i, M) wx[X[i]].push_back({Y[i], W[i]});
forR(i, N) sort(all(wx[i]), [](pii a, pii b){return a.a < b.a;});
vvll wpsa(N);
forR(i, N) if(!wx[i].empty()) {
wpsa[i].push_back(wx[i][0].b);
REP(j, 1, wx[i].size()) wpsa[i].push_back(wx[i][j].b + wpsa[i].back());
}
vector<set<int>> sidPos(N), sePos(N);
forR(i, M) {
if(X[i] > 0) sidPos[X[i]-1].insert(Y[i] + 1);
if(X[i] + 1 < N) sidPos[X[i] + 1].insert(Y[i] + 1);
if(X[i] > 1) sidPos[X[i]-2].insert(Y[i] + 1);
if(X[i] + 2 < N) sidPos[X[i] + 2].insert(Y[i] + 1);
sidPos[X[i]].insert(Y[i]+1);
if(X[i] > 0) sePos[X[i]-1].insert(Y[i] + 1);
if(X[i] + 1 < N) sePos[X[i] + 1].insert(Y[i] + 1);
if(X[i] > 1) sePos[X[i]-2].insert(Y[i] + 1);
if(X[i] + 2 < N) sePos[X[i] + 2].insert(Y[i] + 1);
sePos[X[i]].insert(Y[i]+1);
}
forR(i, N) {
sidPos[i].insert(0);
sePos[i].insert(0);
}
vector<vi> idPos(N), ePos(N);
forR(i, N) {
for(int j : sidPos[i]) idPos[i].push_back(j);
for(int j : sePos[i]) ePos[i].push_back(j);
}
vvll I(N), D(N), E(N);
forR(i, N) I[i].resize(idPos[i].size()), D[i].resize(idPos[i].size()), E[i].resize(ePos[i].size());
// h = HEIGHT, not the index of last element!
forR(i, N) {
ll besIE = -INF, besII = -INF;
if(i > 0) {
forR(ki, ePos[i-1].size()) {
int k = ePos[i-1][ki];
besIE = max(besIE, E[i-1][ki] - rSum(k-1, wx[i-1], wpsa[i-1]));
}
}
int api = 0;
forR(hi, idPos[i].size()) {
int h = idPos[i][hi];
if(h > 0) {
if(i == 0) I[i][hi] = 0;
else {
I[i][hi] = max(I[i][hi], besIE + rSum(h-1, wx[i-1], wpsa[i-1]));
while(api < idPos[i-1].size() && idPos[i-1][api] <= h) {
int k = idPos[i-1][api];
besII = max(besII, I[i-1][api] - rSum(k-1, wx[i-1], wpsa[i-1]));
++api;
}
I[i][hi] = max(I[i][hi], besII + rSum(h-1, wx[i-1], wpsa[i-1]));
}
}
}
api = (int) idPos[i-1].size() - 1;
ll besD = -INF;
for(int hi = (int) idPos[i].size() - 1; hi >= 0; --hi){
int h = idPos[i][hi];
if(h > 0) {
if(i == 0) D[i][hi] = 0;
else {
while(api >= 0 && idPos[i-1][api] >= h + 1) {
int k = idPos[i-1][api];
besD = max(besD, max(I[i-1][api], D[i-1][api]) + rSum(k-1, wx[i], wpsa[i]));
--api;
}
D[i][hi] = max(D[i][hi], besD - rSum(h-1, wx[i], wpsa[i]));
}
}
}
ll besE = -INF;
if(i > 0) {
forR(yi, ePos[i-1].size()) besE = max(besE, E[i-1][yi]);
}
forR(hi, ePos[i].size()){
int h = ePos[i][hi];
if(i == 0) E[i][hi] = 0;
else {
int pInd = lower_bound(all(idPos[i-1]), h) - idPos[i-1].begin();
if(idPos[i-1][pInd] == h) {
ll tot = max(I[i-1][pInd], D[i-1][pInd]) + rSum(h-1, wx[i], wpsa[i]);
E[i][hi] = max(E[i][hi], max(tot, besE));
}
}
}
}
ll mx = 0;
forR(hi, idPos[N-1].size()) mx = max(mx, max(I[N-1][hi], D[N-1][hi]));
forR(hi, ePos[N-1].size()) mx = max(mx, E[N-1][hi]);
return mx;
}
Compilation message
fish.cpp:2:25: warning: extra tokens at end of #include directive
2 | #include "bits/stdc++.h";
| ^
fish.cpp: In function 'long long int max_weights(int, int, std::vector<int>, std::vector<int>, std::vector<int>)':
fish.cpp:5:41: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<pii>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
5 | #define REP(i, a, b) for(int i = (a); i < (b); ++i)
| ^
fish.cpp:30:5: note: in expansion of macro 'REP'
30 | REP(j, 1, wx[i].size()) wpsa[i].push_back(wx[i][j].b + wpsa[i].back());
| ^~~
fish.cpp:4:37: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
4 | #define forR(i, x) for(int i = 0; i < (x); ++i)
| ^
fish.cpp:62:7: note: in expansion of macro 'forR'
62 | forR(ki, ePos[i-1].size()) {
| ^~~~
fish.cpp:4:37: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
4 | #define forR(i, x) for(int i = 0; i < (x); ++i)
| ^
fish.cpp:68:5: note: in expansion of macro 'forR'
68 | forR(hi, idPos[i].size()) {
| ^~~~
fish.cpp:74:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
74 | while(api < idPos[i-1].size() && idPos[i-1][api] <= h) {
| ~~~~^~~~~~~~~~~~~~~~~~~
fish.cpp:4:37: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
4 | #define forR(i, x) for(int i = 0; i < (x); ++i)
| ^
fish.cpp:103:7: note: in expansion of macro 'forR'
103 | forR(yi, ePos[i-1].size()) besE = max(besE, E[i-1][yi]);
| ^~~~
fish.cpp:4:37: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
4 | #define forR(i, x) for(int i = 0; i < (x); ++i)
| ^
fish.cpp:105:5: note: in expansion of macro 'forR'
105 | forR(hi, ePos[i].size()){
| ^~~~
fish.cpp:4:37: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
4 | #define forR(i, x) for(int i = 0; i < (x); ++i)
| ^
fish.cpp:118:3: note: in expansion of macro 'forR'
118 | forR(hi, idPos[N-1].size()) mx = max(mx, max(I[N-1][hi], D[N-1][hi]));
| ^~~~
fish.cpp:4:37: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
4 | #define forR(i, x) for(int i = 0; i < (x); ++i)
| ^
fish.cpp:119:3: note: in expansion of macro 'forR'
119 | forR(hi, ePos[N-1].size()) mx = max(mx, E[N-1][hi]);
| ^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
286 ms |
79584 KB |
Output is correct |
2 |
Correct |
376 ms |
92696 KB |
Output is correct |
3 |
Correct |
36 ms |
51092 KB |
Output is correct |
4 |
Correct |
36 ms |
51292 KB |
Output is correct |
5 |
Execution timed out |
1104 ms |
251172 KB |
Time limit exceeded |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
531 ms |
96232 KB |
Output is correct |
3 |
Correct |
650 ms |
109116 KB |
Output is correct |
4 |
Correct |
277 ms |
79692 KB |
Output is correct |
5 |
Correct |
313 ms |
92740 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
35 ms |
51256 KB |
Output is correct |
11 |
Correct |
36 ms |
51288 KB |
Output is correct |
12 |
Correct |
324 ms |
89956 KB |
Output is correct |
13 |
Correct |
402 ms |
105288 KB |
Output is correct |
14 |
Correct |
289 ms |
84860 KB |
Output is correct |
15 |
Correct |
243 ms |
79048 KB |
Output is correct |
16 |
Correct |
273 ms |
84924 KB |
Output is correct |
17 |
Correct |
316 ms |
94172 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
40 ms |
51320 KB |
Output is correct |
2 |
Correct |
36 ms |
51284 KB |
Output is correct |
3 |
Correct |
79 ms |
56404 KB |
Output is correct |
4 |
Correct |
60 ms |
58964 KB |
Output is correct |
5 |
Correct |
108 ms |
69084 KB |
Output is correct |
6 |
Correct |
108 ms |
69200 KB |
Output is correct |
7 |
Correct |
100 ms |
69200 KB |
Output is correct |
8 |
Correct |
99 ms |
69200 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
604 KB |
Output is correct |
10 |
Correct |
2 ms |
860 KB |
Output is correct |
11 |
Correct |
1 ms |
604 KB |
Output is correct |
12 |
Correct |
1 ms |
860 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
604 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
604 KB |
Output is correct |
10 |
Correct |
2 ms |
860 KB |
Output is correct |
11 |
Correct |
1 ms |
604 KB |
Output is correct |
12 |
Correct |
1 ms |
860 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
604 KB |
Output is correct |
15 |
Correct |
1 ms |
604 KB |
Output is correct |
16 |
Correct |
2 ms |
860 KB |
Output is correct |
17 |
Correct |
62 ms |
11108 KB |
Output is correct |
18 |
Correct |
48 ms |
9808 KB |
Output is correct |
19 |
Correct |
47 ms |
10832 KB |
Output is correct |
20 |
Correct |
41 ms |
8788 KB |
Output is correct |
21 |
Correct |
41 ms |
8560 KB |
Output is correct |
22 |
Correct |
94 ms |
16716 KB |
Output is correct |
23 |
Correct |
20 ms |
5468 KB |
Output is correct |
24 |
Correct |
47 ms |
12120 KB |
Output is correct |
25 |
Correct |
2 ms |
860 KB |
Output is correct |
26 |
Correct |
16 ms |
4408 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
604 KB |
Output is correct |
10 |
Correct |
2 ms |
860 KB |
Output is correct |
11 |
Correct |
1 ms |
604 KB |
Output is correct |
12 |
Correct |
1 ms |
860 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
604 KB |
Output is correct |
15 |
Correct |
1 ms |
604 KB |
Output is correct |
16 |
Correct |
2 ms |
860 KB |
Output is correct |
17 |
Correct |
62 ms |
11108 KB |
Output is correct |
18 |
Correct |
48 ms |
9808 KB |
Output is correct |
19 |
Correct |
47 ms |
10832 KB |
Output is correct |
20 |
Correct |
41 ms |
8788 KB |
Output is correct |
21 |
Correct |
41 ms |
8560 KB |
Output is correct |
22 |
Correct |
94 ms |
16716 KB |
Output is correct |
23 |
Correct |
20 ms |
5468 KB |
Output is correct |
24 |
Correct |
47 ms |
12120 KB |
Output is correct |
25 |
Correct |
2 ms |
860 KB |
Output is correct |
26 |
Correct |
16 ms |
4408 KB |
Output is correct |
27 |
Correct |
5 ms |
3932 KB |
Output is correct |
28 |
Correct |
399 ms |
47036 KB |
Output is correct |
29 |
Correct |
934 ms |
96852 KB |
Output is correct |
30 |
Execution timed out |
1042 ms |
152948 KB |
Time limit exceeded |
31 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
40 ms |
51320 KB |
Output is correct |
2 |
Correct |
36 ms |
51284 KB |
Output is correct |
3 |
Correct |
79 ms |
56404 KB |
Output is correct |
4 |
Correct |
60 ms |
58964 KB |
Output is correct |
5 |
Correct |
108 ms |
69084 KB |
Output is correct |
6 |
Correct |
108 ms |
69200 KB |
Output is correct |
7 |
Correct |
100 ms |
69200 KB |
Output is correct |
8 |
Correct |
99 ms |
69200 KB |
Output is correct |
9 |
Correct |
293 ms |
119376 KB |
Output is correct |
10 |
Correct |
94 ms |
40528 KB |
Output is correct |
11 |
Correct |
184 ms |
81008 KB |
Output is correct |
12 |
Correct |
0 ms |
344 KB |
Output is correct |
13 |
Correct |
1 ms |
344 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 |
35 ms |
51252 KB |
Output is correct |
19 |
Correct |
39 ms |
51292 KB |
Output is correct |
20 |
Correct |
36 ms |
51280 KB |
Output is correct |
21 |
Correct |
36 ms |
51288 KB |
Output is correct |
22 |
Correct |
313 ms |
115796 KB |
Output is correct |
23 |
Correct |
375 ms |
121172 KB |
Output is correct |
24 |
Correct |
461 ms |
132088 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
286 ms |
79584 KB |
Output is correct |
2 |
Correct |
376 ms |
92696 KB |
Output is correct |
3 |
Correct |
36 ms |
51092 KB |
Output is correct |
4 |
Correct |
36 ms |
51292 KB |
Output is correct |
5 |
Execution timed out |
1104 ms |
251172 KB |
Time limit exceeded |
6 |
Halted |
0 ms |
0 KB |
- |