# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1072501 |
2024-08-23T20:36:15 Z |
Boas |
Catfish Farm (IOI22_fish) |
C++17 |
|
1000 ms |
2097152 KB |
#include "fish.h"
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#define loop(x, i) for (int i = 0; i < (x); i++)
#define loop1(x, i) for (int i = 1; i <= (x); i++)
#define rev(x, i) for (int i = (int)(x) - 1; i >= 0; i--)
#define itloop(x) for (auto it = begin(x); x != end(x); it++)
#define itrev(x) for (auto it = rbegin(x); x != rend(x); it++)
#define int long long
#define INF ((int64_t)(4e18 + 1))
#define INF32 ((int32_t)(2e9 + 1))
#define ALL(x) begin(x), end(x)
#define RALL(x) rbegin(x), rend(x)
#define removeIn(x, l) l.erase(find(ALL(l), x))
#define pb push_back
#define sz(x) (int)(x).size()
#define F first
#define S second
#define var const auto &
#define foreach(l) for (var e : l)
typedef int8_t i8;
typedef int16_t i16;
typedef int32_t i32;
typedef int64_t i64;
typedef pair<int, int> ii;
typedef tuple<int, int, int> iii;
typedef tuple<int, int, int, int> iiii;
typedef vector<int> vi;
typedef vector<i32> vi32;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<vvvi> vvvvi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<vii> vvii;
typedef vector<viii> vviii;
typedef set<int> si;
typedef set<ii> sii;
typedef set<iii> siii;
typedef vector<si> vsi;
typedef vector<sii> vsii;
typedef vector<vsi> vvsi;
typedef vector<string> vstr;
typedef vector<vector<string>> vvstr;
typedef vector<bool> vb;
typedef vector<vb> vvb;
int max_weightsB(i32 N, i32 M, vi32 X, vi32 Y, vi32 W)
{
vi pSum0 = {0}, pSum1 = {0};
vi at0(N), at1(N);
loop(M, i)
{
if (X[i] == 0)
at0[Y[i]] = W[i];
else
at1[Y[i]] = W[i];
}
loop(N, i)
{
pSum0.pb(pSum0.back() + at0[i]);
pSum1.pb(pSum1.back() + at1[i]);
}
int res = 0;
loop(N + 1, h1)
{
res = max(res, pSum1.back() - pSum1[h1] + pSum0[h1]);
}
if (N == 2)
return max(pSum0.back(), pSum1.back());
return res;
}
int max_weights(i32 N, i32 M, vi32 X, vi32 Y, vi32 W)
{
if (M == 0)
return 0;
bool allEven = 1;
for (int x : X)
if (x % 2)
allEven = 0;
if (allEven)
return accumulate(ALL(W), 0LL);
if (*max_element(ALL(X)) <= 1)
return max_weightsB(N, M, X, Y, W);
int yCount = *max_element(ALL(Y)) + 2;
vvi wSum(N, vi(yCount));
{
vvi wsAtX(N, vi(yCount));
loop(M, i)
{
wsAtX[X[i]][Y[i]] = W[i];
}
loop(N, x)
{
loop1(yCount - 1, y)
{
wSum[x][y] = wSum[x][y - 1] + wsAtX[x][y - 1];
}
}
}
vvvi dp(vvvi(yCount, vvi(yCount, vi(2)))); // 0: adjacentL, 1: adjacentR
vvvi dp2(vvvi(yCount, vvi(yCount, vi(2)))); // 0: adjacentL, 1: adjacentR
vi maxAll(N);
vvi maxOfHeight(N, vi(yCount));
loop(N, x)
{
vvi pMax1perJ(yCount, vi(yCount)); // dp[<=j][i][1]
if (x != 0)
{
loop(yCount, j)
{
loop(yCount, i)
{
pMax1perJ[j][i] = max(j == 0 ? 0 : pMax1perJ[j - 1][i], dp[j][i][1]);
}
}
}
loop(yCount, j)
{
int prevMax = 0;
if (x != 0)
{
loop(yCount, i)
{
prevMax = max(prevMax, dp[j][i][0]);
}
}
loop(yCount, i) // hoogte van deze steiger
{
if (j <= i)
{
dp2[i][j][0] = dp2[i][j][1] = (x == 0) ? 0 : maxOfHeight[x - 1][i];
}
else
{
int sum = wSum[x][j] - wSum[x][i];
if (x == 0)
{
dp2[i][j][0] = -1;
dp2[i][j][1] = sum;
}
else
{
dp2[i][j][0] = max(dp[j][i][1], prevMax) + sum;
dp2[i][j][1] = max(pMax1perJ[j][i], maxAll[x - 1]) + sum;
}
}
maxAll[x] = max({maxAll[x], dp2[i][j][0]});
maxOfHeight[x][j] = max({maxOfHeight[x][j], dp2[i][j][0], dp2[i][j][1]});
}
}
dp = dp2;
}
return maxAll.back();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
2136 KB |
Output is correct |
2 |
Correct |
17 ms |
2652 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
53 ms |
7272 KB |
Output is correct |
6 |
Correct |
51 ms |
7248 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
30 ms |
9128 KB |
Output is correct |
3 |
Correct |
44 ms |
14268 KB |
Output is correct |
4 |
Correct |
15 ms |
3676 KB |
Output is correct |
5 |
Correct |
18 ms |
4444 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 |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
18 ms |
7792 KB |
Output is correct |
13 |
Correct |
21 ms |
8888 KB |
Output is correct |
14 |
Correct |
19 ms |
7876 KB |
Output is correct |
15 |
Correct |
28 ms |
8392 KB |
Output is correct |
16 |
Correct |
17 ms |
7888 KB |
Output is correct |
17 |
Correct |
20 ms |
8400 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
25 ms |
12148 KB |
Output is correct |
3 |
Correct |
31 ms |
12060 KB |
Output is correct |
4 |
Correct |
31 ms |
12992 KB |
Output is correct |
5 |
Correct |
39 ms |
14524 KB |
Output is correct |
6 |
Correct |
38 ms |
15152 KB |
Output is correct |
7 |
Correct |
39 ms |
15404 KB |
Output is correct |
8 |
Correct |
40 ms |
15400 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
344 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 |
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 |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
2 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
344 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 |
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 |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
2 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
344 KB |
Output is correct |
15 |
Correct |
424 ms |
12548 KB |
Output is correct |
16 |
Correct |
7 ms |
1112 KB |
Output is correct |
17 |
Correct |
440 ms |
13608 KB |
Output is correct |
18 |
Correct |
454 ms |
13592 KB |
Output is correct |
19 |
Correct |
445 ms |
13596 KB |
Output is correct |
20 |
Correct |
437 ms |
13612 KB |
Output is correct |
21 |
Correct |
108 ms |
4924 KB |
Output is correct |
22 |
Correct |
448 ms |
14644 KB |
Output is correct |
23 |
Correct |
435 ms |
12820 KB |
Output is correct |
24 |
Correct |
430 ms |
13232 KB |
Output is correct |
25 |
Correct |
3 ms |
604 KB |
Output is correct |
26 |
Correct |
439 ms |
12872 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
344 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 |
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 |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
2 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
344 KB |
Output is correct |
15 |
Correct |
424 ms |
12548 KB |
Output is correct |
16 |
Correct |
7 ms |
1112 KB |
Output is correct |
17 |
Correct |
440 ms |
13608 KB |
Output is correct |
18 |
Correct |
454 ms |
13592 KB |
Output is correct |
19 |
Correct |
445 ms |
13596 KB |
Output is correct |
20 |
Correct |
437 ms |
13612 KB |
Output is correct |
21 |
Correct |
108 ms |
4924 KB |
Output is correct |
22 |
Correct |
448 ms |
14644 KB |
Output is correct |
23 |
Correct |
435 ms |
12820 KB |
Output is correct |
24 |
Correct |
430 ms |
13232 KB |
Output is correct |
25 |
Correct |
3 ms |
604 KB |
Output is correct |
26 |
Correct |
439 ms |
12872 KB |
Output is correct |
27 |
Execution timed out |
1096 ms |
1198980 KB |
Time limit exceeded |
28 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
25 ms |
12148 KB |
Output is correct |
3 |
Correct |
31 ms |
12060 KB |
Output is correct |
4 |
Correct |
31 ms |
12992 KB |
Output is correct |
5 |
Correct |
39 ms |
14524 KB |
Output is correct |
6 |
Correct |
38 ms |
15152 KB |
Output is correct |
7 |
Correct |
39 ms |
15404 KB |
Output is correct |
8 |
Correct |
40 ms |
15400 KB |
Output is correct |
9 |
Runtime error |
743 ms |
2097152 KB |
Execution killed with signal 9 |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
2136 KB |
Output is correct |
2 |
Correct |
17 ms |
2652 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
53 ms |
7272 KB |
Output is correct |
6 |
Correct |
51 ms |
7248 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
30 ms |
9128 KB |
Output is correct |
9 |
Correct |
44 ms |
14268 KB |
Output is correct |
10 |
Correct |
15 ms |
3676 KB |
Output is correct |
11 |
Correct |
18 ms |
4444 KB |
Output is correct |
12 |
Correct |
0 ms |
348 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 |
7792 KB |
Output is correct |
19 |
Correct |
21 ms |
8888 KB |
Output is correct |
20 |
Correct |
19 ms |
7876 KB |
Output is correct |
21 |
Correct |
28 ms |
8392 KB |
Output is correct |
22 |
Correct |
17 ms |
7888 KB |
Output is correct |
23 |
Correct |
20 ms |
8400 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
25 ms |
12148 KB |
Output is correct |
26 |
Correct |
31 ms |
12060 KB |
Output is correct |
27 |
Correct |
31 ms |
12992 KB |
Output is correct |
28 |
Correct |
39 ms |
14524 KB |
Output is correct |
29 |
Correct |
38 ms |
15152 KB |
Output is correct |
30 |
Correct |
39 ms |
15404 KB |
Output is correct |
31 |
Correct |
40 ms |
15400 KB |
Output is correct |
32 |
Correct |
0 ms |
348 KB |
Output is correct |
33 |
Correct |
1 ms |
348 KB |
Output is correct |
34 |
Correct |
0 ms |
344 KB |
Output is correct |
35 |
Correct |
0 ms |
348 KB |
Output is correct |
36 |
Correct |
0 ms |
348 KB |
Output is correct |
37 |
Correct |
0 ms |
348 KB |
Output is correct |
38 |
Correct |
0 ms |
348 KB |
Output is correct |
39 |
Correct |
0 ms |
348 KB |
Output is correct |
40 |
Correct |
0 ms |
348 KB |
Output is correct |
41 |
Correct |
1 ms |
348 KB |
Output is correct |
42 |
Correct |
1 ms |
348 KB |
Output is correct |
43 |
Correct |
2 ms |
348 KB |
Output is correct |
44 |
Correct |
0 ms |
348 KB |
Output is correct |
45 |
Correct |
1 ms |
344 KB |
Output is correct |
46 |
Correct |
424 ms |
12548 KB |
Output is correct |
47 |
Correct |
7 ms |
1112 KB |
Output is correct |
48 |
Correct |
440 ms |
13608 KB |
Output is correct |
49 |
Correct |
454 ms |
13592 KB |
Output is correct |
50 |
Correct |
445 ms |
13596 KB |
Output is correct |
51 |
Correct |
437 ms |
13612 KB |
Output is correct |
52 |
Correct |
108 ms |
4924 KB |
Output is correct |
53 |
Correct |
448 ms |
14644 KB |
Output is correct |
54 |
Correct |
435 ms |
12820 KB |
Output is correct |
55 |
Correct |
430 ms |
13232 KB |
Output is correct |
56 |
Correct |
3 ms |
604 KB |
Output is correct |
57 |
Correct |
439 ms |
12872 KB |
Output is correct |
58 |
Execution timed out |
1096 ms |
1198980 KB |
Time limit exceeded |
59 |
Halted |
0 ms |
0 KB |
- |