# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1112527 | 2024-11-14T09:32:05 Z | starchan | Catfish Farm (IOI22_fish) | C++17 | 163 ms | 51164 KB |
#include "fish.h" #include<bits/stdc++.h> using namespace std; #define ll long long #define in array<int, 2> #define iln array<ll, 2> #define pb push_back #define pob pop_back const ll INF = 1e17; ll max_weights(int n, int m, vector<int> x, vector<int> y, vector<int> w) { vector<in> loc[n+1];//loc[i][k] = kth from bottom in ith column. for(auto &s: x) s++; for(auto &s: y) s++; for(int i = 1; i <= n; i++) loc[i].pb({0, 0}); for(int i = 0; i < m; i++) loc[x[i]].pb({y[i], w[i]}); //pre-processing done. vector<array<ll, 4>> dp[n+1]; vector<ll> pref[n+1]; ll DP[n+1]; for(int i = 1; i <= n; i++) { sort(loc[i].begin(), loc[i].end()); loc[i].pb({n+1, 0}); pref[i].assign(loc[i].size(), 0ll); for(int j = 1; j < loc[i].size(); j++) pref[i][j] = pref[i][j-1] + loc[i][j][1]; dp[i].resize(loc[i].size()); } DP[0] = DP[1] = 0; for(int i = 2; i <= n; i++) { dp[i][0][0] = dp[i-1][0][0]; int D = loc[i-1].size()-1; ll Val = dp[i-1][D][0] + pref[i].back(); for(int j = loc[i].size()-1; j >= 0; j--) { while((D > 0) && (loc[i-1][D-1][0] > loc[i][j][0])) { D--; Val = max(Val, dp[i-1][D][0] + pref[i][j]); } if(j) dp[i][j][3] = Val - pref[i][j-1]; else dp[i][j][3] = Val; } dp[i][0][0] = max(dp[i][0][0], dp[i][0][3]); int Dd = 0; ll VAL = -INF; for(int j = 1; j < loc[i].size(); j++) { dp[i][j][1] = dp[i-1][0][0]; while(((Dd+1) < loc[i-1].size()) && (loc[i-1][Dd+1][0] < loc[i][j][0])) { Dd++; VAL = max(VAL, dp[i-1][Dd][2] - pref[i-1][Dd-1]); } dp[i][j][2] = max(DP[i-2], VAL) + pref[i-1][Dd]; } DP[i] = dp[i][0][0]; for(int j = 1; j < loc[i].size(); j++) { dp[i][j][0] = max(max(dp[i][j][1], dp[i][j][2]), dp[i][j][3]); DP[i] = max(DP[i], dp[i][j][0]); } } return DP[n]; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 53 ms | 27068 KB | Output is correct |
2 | Correct | 63 ms | 30996 KB | Output is correct |
3 | Correct | 34 ms | 22352 KB | Output is correct |
4 | Correct | 31 ms | 22352 KB | Output is correct |
5 | Correct | 118 ms | 49704 KB | Output is correct |
6 | Correct | 128 ms | 51164 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 336 KB | Output is correct |
2 | Correct | 73 ms | 34260 KB | Output is correct |
3 | Correct | 86 ms | 39860 KB | Output is correct |
4 | Correct | 48 ms | 27068 KB | Output is correct |
5 | Correct | 61 ms | 30928 KB | Output is correct |
6 | Correct | 1 ms | 336 KB | Output is correct |
7 | Correct | 1 ms | 336 KB | Output is correct |
8 | Correct | 1 ms | 508 KB | Output is correct |
9 | Correct | 1 ms | 336 KB | Output is correct |
10 | Correct | 37 ms | 22344 KB | Output is correct |
11 | Correct | 28 ms | 22236 KB | Output is correct |
12 | Correct | 50 ms | 27068 KB | Output is correct |
13 | Correct | 57 ms | 30896 KB | Output is correct |
14 | Correct | 50 ms | 27068 KB | Output is correct |
15 | Correct | 54 ms | 30112 KB | Output is correct |
16 | Correct | 50 ms | 27100 KB | Output is correct |
17 | Correct | 55 ms | 30152 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 28 ms | 22352 KB | Output is correct |
2 | Correct | 29 ms | 22352 KB | Output is correct |
3 | Correct | 42 ms | 24648 KB | Output is correct |
4 | Correct | 41 ms | 25416 KB | Output is correct |
5 | Correct | 75 ms | 30792 KB | Output is correct |
6 | Correct | 62 ms | 30232 KB | Output is correct |
7 | Correct | 63 ms | 30792 KB | Output is correct |
8 | Correct | 68 ms | 30772 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 336 KB | Output is correct |
2 | Correct | 1 ms | 336 KB | Output is correct |
3 | Correct | 1 ms | 336 KB | Output is correct |
4 | Correct | 1 ms | 336 KB | Output is correct |
5 | Correct | 1 ms | 504 KB | Output is correct |
6 | Correct | 1 ms | 336 KB | Output is correct |
7 | Correct | 1 ms | 336 KB | Output is correct |
8 | Correct | 1 ms | 336 KB | Output is correct |
9 | Correct | 1 ms | 336 KB | Output is correct |
10 | Correct | 1 ms | 592 KB | Output is correct |
11 | Correct | 1 ms | 336 KB | Output is correct |
12 | Correct | 1 ms | 592 KB | Output is correct |
13 | Correct | 1 ms | 336 KB | Output is correct |
14 | Correct | 1 ms | 336 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 336 KB | Output is correct |
2 | Correct | 1 ms | 336 KB | Output is correct |
3 | Correct | 1 ms | 336 KB | Output is correct |
4 | Correct | 1 ms | 336 KB | Output is correct |
5 | Correct | 1 ms | 504 KB | Output is correct |
6 | Correct | 1 ms | 336 KB | Output is correct |
7 | Correct | 1 ms | 336 KB | Output is correct |
8 | Correct | 1 ms | 336 KB | Output is correct |
9 | Correct | 1 ms | 336 KB | Output is correct |
10 | Correct | 1 ms | 592 KB | Output is correct |
11 | Correct | 1 ms | 336 KB | Output is correct |
12 | Correct | 1 ms | 592 KB | Output is correct |
13 | Correct | 1 ms | 336 KB | Output is correct |
14 | Correct | 1 ms | 336 KB | Output is correct |
15 | Correct | 1 ms | 336 KB | Output is correct |
16 | Correct | 2 ms | 592 KB | Output is correct |
17 | Correct | 15 ms | 4432 KB | Output is correct |
18 | Correct | 14 ms | 4688 KB | Output is correct |
19 | Correct | 15 ms | 4532 KB | Output is correct |
20 | Correct | 17 ms | 4656 KB | Output is correct |
21 | Correct | 15 ms | 4688 KB | Output is correct |
22 | Correct | 28 ms | 8800 KB | Output is correct |
23 | Correct | 4 ms | 1104 KB | Output is correct |
24 | Correct | 9 ms | 3320 KB | Output is correct |
25 | Correct | 1 ms | 592 KB | Output is correct |
26 | Correct | 4 ms | 1104 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 336 KB | Output is correct |
2 | Correct | 1 ms | 336 KB | Output is correct |
3 | Correct | 1 ms | 336 KB | Output is correct |
4 | Correct | 1 ms | 336 KB | Output is correct |
5 | Correct | 1 ms | 504 KB | Output is correct |
6 | Correct | 1 ms | 336 KB | Output is correct |
7 | Correct | 1 ms | 336 KB | Output is correct |
8 | Correct | 1 ms | 336 KB | Output is correct |
9 | Correct | 1 ms | 336 KB | Output is correct |
10 | Correct | 1 ms | 592 KB | Output is correct |
11 | Correct | 1 ms | 336 KB | Output is correct |
12 | Correct | 1 ms | 592 KB | Output is correct |
13 | Correct | 1 ms | 336 KB | Output is correct |
14 | Correct | 1 ms | 336 KB | Output is correct |
15 | Correct | 1 ms | 336 KB | Output is correct |
16 | Correct | 2 ms | 592 KB | Output is correct |
17 | Correct | 15 ms | 4432 KB | Output is correct |
18 | Correct | 14 ms | 4688 KB | Output is correct |
19 | Correct | 15 ms | 4532 KB | Output is correct |
20 | Correct | 17 ms | 4656 KB | Output is correct |
21 | Correct | 15 ms | 4688 KB | Output is correct |
22 | Correct | 28 ms | 8800 KB | Output is correct |
23 | Correct | 4 ms | 1104 KB | Output is correct |
24 | Correct | 9 ms | 3320 KB | Output is correct |
25 | Correct | 1 ms | 592 KB | Output is correct |
26 | Correct | 4 ms | 1104 KB | Output is correct |
27 | Correct | 3 ms | 1104 KB | Output is correct |
28 | Correct | 69 ms | 20868 KB | Output is correct |
29 | Correct | 106 ms | 28620 KB | Output is correct |
30 | Correct | 91 ms | 28520 KB | Output is correct |
31 | Correct | 93 ms | 28488 KB | Output is correct |
32 | Correct | 88 ms | 29008 KB | Output is correct |
33 | Correct | 95 ms | 28492 KB | Output is correct |
34 | Correct | 102 ms | 28488 KB | Output is correct |
35 | Correct | 34 ms | 11512 KB | Output is correct |
36 | Correct | 93 ms | 29000 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 28 ms | 22352 KB | Output is correct |
2 | Correct | 29 ms | 22352 KB | Output is correct |
3 | Correct | 42 ms | 24648 KB | Output is correct |
4 | Correct | 41 ms | 25416 KB | Output is correct |
5 | Correct | 75 ms | 30792 KB | Output is correct |
6 | Correct | 62 ms | 30232 KB | Output is correct |
7 | Correct | 63 ms | 30792 KB | Output is correct |
8 | Correct | 68 ms | 30772 KB | Output is correct |
9 | Correct | 59 ms | 30536 KB | Output is correct |
10 | Correct | 45 ms | 20440 KB | Output is correct |
11 | Correct | 100 ms | 40656 KB | Output is correct |
12 | Correct | 1 ms | 336 KB | Output is correct |
13 | Correct | 1 ms | 336 KB | Output is correct |
14 | Correct | 1 ms | 436 KB | Output is correct |
15 | Correct | 1 ms | 336 KB | Output is correct |
16 | Correct | 1 ms | 336 KB | Output is correct |
17 | Correct | 1 ms | 336 KB | Output is correct |
18 | Correct | 30 ms | 22168 KB | Output is correct |
19 | Correct | 29 ms | 22344 KB | Output is correct |
20 | Correct | 28 ms | 22352 KB | Output is correct |
21 | Correct | 29 ms | 22352 KB | Output is correct |
22 | Correct | 73 ms | 31572 KB | Output is correct |
23 | Correct | 104 ms | 40796 KB | Output is correct |
24 | Correct | 108 ms | 41288 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 53 ms | 27068 KB | Output is correct |
2 | Correct | 63 ms | 30996 KB | Output is correct |
3 | Correct | 34 ms | 22352 KB | Output is correct |
4 | Correct | 31 ms | 22352 KB | Output is correct |
5 | Correct | 118 ms | 49704 KB | Output is correct |
6 | Correct | 128 ms | 51164 KB | Output is correct |
7 | Correct | 1 ms | 336 KB | Output is correct |
8 | Correct | 73 ms | 34260 KB | Output is correct |
9 | Correct | 86 ms | 39860 KB | Output is correct |
10 | Correct | 48 ms | 27068 KB | Output is correct |
11 | Correct | 61 ms | 30928 KB | Output is correct |
12 | Correct | 1 ms | 336 KB | Output is correct |
13 | Correct | 1 ms | 336 KB | Output is correct |
14 | Correct | 1 ms | 508 KB | Output is correct |
15 | Correct | 1 ms | 336 KB | Output is correct |
16 | Correct | 37 ms | 22344 KB | Output is correct |
17 | Correct | 28 ms | 22236 KB | Output is correct |
18 | Correct | 50 ms | 27068 KB | Output is correct |
19 | Correct | 57 ms | 30896 KB | Output is correct |
20 | Correct | 50 ms | 27068 KB | Output is correct |
21 | Correct | 54 ms | 30112 KB | Output is correct |
22 | Correct | 50 ms | 27100 KB | Output is correct |
23 | Correct | 55 ms | 30152 KB | Output is correct |
24 | Correct | 28 ms | 22352 KB | Output is correct |
25 | Correct | 29 ms | 22352 KB | Output is correct |
26 | Correct | 42 ms | 24648 KB | Output is correct |
27 | Correct | 41 ms | 25416 KB | Output is correct |
28 | Correct | 75 ms | 30792 KB | Output is correct |
29 | Correct | 62 ms | 30232 KB | Output is correct |
30 | Correct | 63 ms | 30792 KB | Output is correct |
31 | Correct | 68 ms | 30772 KB | Output is correct |
32 | Correct | 1 ms | 336 KB | Output is correct |
33 | Correct | 1 ms | 336 KB | Output is correct |
34 | Correct | 1 ms | 336 KB | Output is correct |
35 | Correct | 1 ms | 336 KB | Output is correct |
36 | Correct | 1 ms | 504 KB | Output is correct |
37 | Correct | 1 ms | 336 KB | Output is correct |
38 | Correct | 1 ms | 336 KB | Output is correct |
39 | Correct | 1 ms | 336 KB | Output is correct |
40 | Correct | 1 ms | 336 KB | Output is correct |
41 | Correct | 1 ms | 592 KB | Output is correct |
42 | Correct | 1 ms | 336 KB | Output is correct |
43 | Correct | 1 ms | 592 KB | Output is correct |
44 | Correct | 1 ms | 336 KB | Output is correct |
45 | Correct | 1 ms | 336 KB | Output is correct |
46 | Correct | 1 ms | 336 KB | Output is correct |
47 | Correct | 2 ms | 592 KB | Output is correct |
48 | Correct | 15 ms | 4432 KB | Output is correct |
49 | Correct | 14 ms | 4688 KB | Output is correct |
50 | Correct | 15 ms | 4532 KB | Output is correct |
51 | Correct | 17 ms | 4656 KB | Output is correct |
52 | Correct | 15 ms | 4688 KB | Output is correct |
53 | Correct | 28 ms | 8800 KB | Output is correct |
54 | Correct | 4 ms | 1104 KB | Output is correct |
55 | Correct | 9 ms | 3320 KB | Output is correct |
56 | Correct | 1 ms | 592 KB | Output is correct |
57 | Correct | 4 ms | 1104 KB | Output is correct |
58 | Correct | 3 ms | 1104 KB | Output is correct |
59 | Correct | 69 ms | 20868 KB | Output is correct |
60 | Correct | 106 ms | 28620 KB | Output is correct |
61 | Correct | 91 ms | 28520 KB | Output is correct |
62 | Correct | 93 ms | 28488 KB | Output is correct |
63 | Correct | 88 ms | 29008 KB | Output is correct |
64 | Correct | 95 ms | 28492 KB | Output is correct |
65 | Correct | 102 ms | 28488 KB | Output is correct |
66 | Correct | 34 ms | 11512 KB | Output is correct |
67 | Correct | 93 ms | 29000 KB | Output is correct |
68 | Correct | 59 ms | 30536 KB | Output is correct |
69 | Correct | 45 ms | 20440 KB | Output is correct |
70 | Correct | 100 ms | 40656 KB | Output is correct |
71 | Correct | 1 ms | 336 KB | Output is correct |
72 | Correct | 1 ms | 336 KB | Output is correct |
73 | Correct | 1 ms | 436 KB | Output is correct |
74 | Correct | 1 ms | 336 KB | Output is correct |
75 | Correct | 1 ms | 336 KB | Output is correct |
76 | Correct | 1 ms | 336 KB | Output is correct |
77 | Correct | 30 ms | 22168 KB | Output is correct |
78 | Correct | 29 ms | 22344 KB | Output is correct |
79 | Correct | 28 ms | 22352 KB | Output is correct |
80 | Correct | 29 ms | 22352 KB | Output is correct |
81 | Correct | 73 ms | 31572 KB | Output is correct |
82 | Correct | 104 ms | 40796 KB | Output is correct |
83 | Correct | 108 ms | 41288 KB | Output is correct |
84 | Correct | 132 ms | 47416 KB | Output is correct |
85 | Correct | 125 ms | 49280 KB | Output is correct |
86 | Correct | 136 ms | 48456 KB | Output is correct |
87 | Correct | 147 ms | 50760 KB | Output is correct |
88 | Correct | 1 ms | 336 KB | Output is correct |
89 | Correct | 163 ms | 50764 KB | Output is correct |
90 | Correct | 135 ms | 49756 KB | Output is correct |
91 | Correct | 137 ms | 49736 KB | Output is correct |