# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
841216 |
2023-09-01T11:30:43 Z |
Cookie |
Catfish Farm (IOI22_fish) |
C++17 |
|
914 ms |
186272 KB |
#include "fish.h"
#include<bits/stdc++.h>
#include<fstream>
using namespace std;
//ifstream fin("FEEDING.INP");
//ofstream fout("FEEDING.OUT");
#define sz(a) (int)a.size()
#define ll long long
#define pb push_back
#define forr(i, a, b) for(int i = a; i < b; i++)
#define dorr(i, a, b) for(int i = a; i >= b; i--)
#define ld long double
#define vt vector
#include<fstream>
#define fi first
#define se second
#define pll pair<ll, ll>
#define pii pair<int, int>
const int mxn = 1e5 + 5;
int n, m;
ll x[3 * mxn + 1], y[3 * mxn + 1], w[3 * mxn + 1];
vt<ll> take[mxn + 1], notake[mxn + 1], pref[mxn + 1];
ll mxval[mxn + 1];
vt<ll> prefmx[mxn + 1], sufmx[mxn + 1], prefmx2[mxn + 1], sufmx2[mxn + 1];
vt<ll>comp[mxn + 1];
void ckmax(ll &a, ll b){
a = max(a, b);
}
int getr(int id, int x){
return(lower_bound(comp[id].begin(), comp[id].end(), x) - comp[id].begin() + 1);
}
int getl(int id, int x){
return(upper_bound(comp[id].begin(), comp[id].end(), x) - comp[id].begin());
}
ll solve(){
ll ans = 0;
for(int i = 1; i <= n; i++){
for(int j = 1; j <= sz(comp[i]); j++){
if(i > 1){
notake[i][j] = take[i][j] = pref[i - 1][getl(i - 1, comp[i][j - 1])];
ckmax(take[i][j], sufmx[i - 1][getr(i - 1, comp[i][j - 1])] - pref[i][j]);
ckmax(take[i][j], prefmx[i - 1][getl(i - 1, comp[i][j - 1])]);
ckmax(take[i][j], prefmx2[i - 1][getl(i - 1, comp[i][j - 1])] + pref[i - 1][getl(i - 1, comp[i][j - 1])]);
ckmax(notake[i][j], prefmx[i - 1][sz(comp[i - 1])]);
ckmax(notake[i][j], prefmx2[i - 1][getl(i - 1, comp[i][j - 1])] + pref[i - 1][getl(i - 1, comp[i][j - 1])]);
}
if(i > 2){
ckmax(take[i][j], prefmx[i - 2][getl(i - 2, comp[i][j - 1])] + pref[i - 1][getl(i - 1, comp[i][j - 1])]);
ckmax(take[i][j], sufmx[i - 2][getr(i - 2, comp[i][j - 1])]);
}if(i > 3){
ckmax(take[i][j], mxval[i - 3] + pref[i - 1][getl(i - 1, comp[i][j - 1])]);
ckmax(notake[i][j], mxval[i - 3] + pref[i - 1][getl(i - 1, comp[i][j - 1])]);
}
ll tmp = take[i][j];
if(i < n){
tmp += pref[i + 1][getl(i + 1, comp[i][j - 1])];
}
ckmax(ans, tmp);
if(i < n)ckmax(mxval[i], take[i][j] + pref[i + 1][getl(i + 1, comp[i][j - 1])]);
//cout << i << " " << comp[i][j - 1] << " " << take[i][j] << "\n";
}
for(int j = 1; j <= sz(comp[i]); j++){
prefmx[i][j] = max(prefmx[i][j - 1], take[i][j]);
prefmx2[i][j] = max(prefmx2[i][j - 1], notake[i][j] - pref[i][j]);
}
for(int j = sz(comp[i]); j >= 1; j--){
if(i < n)sufmx[i][j] = max(sufmx[i][j + 1], take[i][j] + pref[i + 1][getl(i + 1, comp[i][j - 1])]);
}
// sp3[i].init();
}
return(ans);
}
map<int, ll>cost[mxn + 1];
long long max_weights(int N, int M, std::vector<int> X, std::vector<int> Y, std::vector<int> W){
n = N; m = M;
ll ans =0;
for(int i = 1; i <= m; i++){
x[i] = ++X[i - 1]; y[i] = ++Y[i - 1]; w[i] = W[i - 1];
cost[x[i]][y[i]] += w[i];
for(int j = max(x[i] - 1, (ll)1); j <= min(x[i] + 1, (ll)n); j++){
comp[j].pb(y[i]);
}
}
for(int i = 1; i <= n; i++){
comp[i].pb(1);
sort(comp[i].begin(), comp[i].end());
comp[i].resize(unique(comp[i].begin(), comp[i].end()) - comp[i].begin());
int need = sz(comp[i]) + 3;
take[i].resize(need); notake[i].resize(need); pref[i].resize(need); prefmx[i].resize(need); prefmx2[i].resize(need); sufmx[i].resize(need);
}
for(int i = 1; i <= n; i++){
for(int j = 1; j <= sz(comp[i]); j++){
pref[i][j] = pref[i][j - 1] + cost[i][comp[i][j - 1]];
}
}
return(solve());
}
/*
int main() {
int N, M;
assert(2 == scanf("%d %d", &N, &M));
std::vector<int> X(M), Y(M), W(M);
for (int i = 0; i < M; ++i) {
assert(3 == scanf("%d %d %d", &X[i], &Y[i], &W[i]));
}
long long result = max_weights(N, M, X, Y, W);
printf("%lld\n", result);
return 0;
}
*/
//741526820812
Compilation message
fish.cpp: In function 'long long int max_weights(int, int, std::vector<int>, std::vector<int>, std::vector<int>)':
fish.cpp:91:8: warning: unused variable 'ans' [-Wunused-variable]
91 | ll ans =0;
| ^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
159 ms |
82388 KB |
Output is correct |
2 |
Correct |
196 ms |
92104 KB |
Output is correct |
3 |
Correct |
65 ms |
62028 KB |
Output is correct |
4 |
Correct |
62 ms |
62028 KB |
Output is correct |
5 |
Correct |
818 ms |
184732 KB |
Output is correct |
6 |
Correct |
623 ms |
185568 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
23764 KB |
Output is correct |
2 |
Correct |
307 ms |
100288 KB |
Output is correct |
3 |
Correct |
385 ms |
111172 KB |
Output is correct |
4 |
Correct |
163 ms |
82484 KB |
Output is correct |
5 |
Correct |
193 ms |
92104 KB |
Output is correct |
6 |
Correct |
11 ms |
23764 KB |
Output is correct |
7 |
Correct |
10 ms |
23764 KB |
Output is correct |
8 |
Correct |
10 ms |
23764 KB |
Output is correct |
9 |
Correct |
11 ms |
23892 KB |
Output is correct |
10 |
Correct |
60 ms |
62028 KB |
Output is correct |
11 |
Correct |
60 ms |
62148 KB |
Output is correct |
12 |
Correct |
217 ms |
92208 KB |
Output is correct |
13 |
Correct |
278 ms |
103872 KB |
Output is correct |
14 |
Correct |
210 ms |
87260 KB |
Output is correct |
15 |
Correct |
200 ms |
85452 KB |
Output is correct |
16 |
Correct |
213 ms |
87348 KB |
Output is correct |
17 |
Correct |
244 ms |
94372 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
61 ms |
62148 KB |
Output is correct |
2 |
Correct |
61 ms |
62152 KB |
Output is correct |
3 |
Correct |
100 ms |
62668 KB |
Output is correct |
4 |
Correct |
92 ms |
64952 KB |
Output is correct |
5 |
Correct |
127 ms |
70788 KB |
Output is correct |
6 |
Correct |
130 ms |
70092 KB |
Output is correct |
7 |
Correct |
136 ms |
70732 KB |
Output is correct |
8 |
Correct |
133 ms |
70732 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
23892 KB |
Output is correct |
2 |
Correct |
10 ms |
23764 KB |
Output is correct |
3 |
Correct |
12 ms |
23820 KB |
Output is correct |
4 |
Correct |
12 ms |
23764 KB |
Output is correct |
5 |
Correct |
11 ms |
23764 KB |
Output is correct |
6 |
Correct |
11 ms |
23764 KB |
Output is correct |
7 |
Correct |
10 ms |
23764 KB |
Output is correct |
8 |
Correct |
14 ms |
23980 KB |
Output is correct |
9 |
Correct |
10 ms |
23892 KB |
Output is correct |
10 |
Correct |
12 ms |
24276 KB |
Output is correct |
11 |
Correct |
14 ms |
24020 KB |
Output is correct |
12 |
Correct |
11 ms |
24148 KB |
Output is correct |
13 |
Correct |
10 ms |
23796 KB |
Output is correct |
14 |
Correct |
10 ms |
24020 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
23892 KB |
Output is correct |
2 |
Correct |
10 ms |
23764 KB |
Output is correct |
3 |
Correct |
12 ms |
23820 KB |
Output is correct |
4 |
Correct |
12 ms |
23764 KB |
Output is correct |
5 |
Correct |
11 ms |
23764 KB |
Output is correct |
6 |
Correct |
11 ms |
23764 KB |
Output is correct |
7 |
Correct |
10 ms |
23764 KB |
Output is correct |
8 |
Correct |
14 ms |
23980 KB |
Output is correct |
9 |
Correct |
10 ms |
23892 KB |
Output is correct |
10 |
Correct |
12 ms |
24276 KB |
Output is correct |
11 |
Correct |
14 ms |
24020 KB |
Output is correct |
12 |
Correct |
11 ms |
24148 KB |
Output is correct |
13 |
Correct |
10 ms |
23796 KB |
Output is correct |
14 |
Correct |
10 ms |
24020 KB |
Output is correct |
15 |
Correct |
11 ms |
24020 KB |
Output is correct |
16 |
Correct |
13 ms |
24276 KB |
Output is correct |
17 |
Correct |
68 ms |
34892 KB |
Output is correct |
18 |
Correct |
61 ms |
33740 KB |
Output is correct |
19 |
Correct |
61 ms |
33876 KB |
Output is correct |
20 |
Correct |
57 ms |
32972 KB |
Output is correct |
21 |
Correct |
63 ms |
33004 KB |
Output is correct |
22 |
Correct |
113 ms |
41916 KB |
Output is correct |
23 |
Correct |
28 ms |
27476 KB |
Output is correct |
24 |
Correct |
61 ms |
33868 KB |
Output is correct |
25 |
Correct |
13 ms |
24276 KB |
Output is correct |
26 |
Correct |
29 ms |
26964 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
23892 KB |
Output is correct |
2 |
Correct |
10 ms |
23764 KB |
Output is correct |
3 |
Correct |
12 ms |
23820 KB |
Output is correct |
4 |
Correct |
12 ms |
23764 KB |
Output is correct |
5 |
Correct |
11 ms |
23764 KB |
Output is correct |
6 |
Correct |
11 ms |
23764 KB |
Output is correct |
7 |
Correct |
10 ms |
23764 KB |
Output is correct |
8 |
Correct |
14 ms |
23980 KB |
Output is correct |
9 |
Correct |
10 ms |
23892 KB |
Output is correct |
10 |
Correct |
12 ms |
24276 KB |
Output is correct |
11 |
Correct |
14 ms |
24020 KB |
Output is correct |
12 |
Correct |
11 ms |
24148 KB |
Output is correct |
13 |
Correct |
10 ms |
23796 KB |
Output is correct |
14 |
Correct |
10 ms |
24020 KB |
Output is correct |
15 |
Correct |
11 ms |
24020 KB |
Output is correct |
16 |
Correct |
13 ms |
24276 KB |
Output is correct |
17 |
Correct |
68 ms |
34892 KB |
Output is correct |
18 |
Correct |
61 ms |
33740 KB |
Output is correct |
19 |
Correct |
61 ms |
33876 KB |
Output is correct |
20 |
Correct |
57 ms |
32972 KB |
Output is correct |
21 |
Correct |
63 ms |
33004 KB |
Output is correct |
22 |
Correct |
113 ms |
41916 KB |
Output is correct |
23 |
Correct |
28 ms |
27476 KB |
Output is correct |
24 |
Correct |
61 ms |
33868 KB |
Output is correct |
25 |
Correct |
13 ms |
24276 KB |
Output is correct |
26 |
Correct |
29 ms |
26964 KB |
Output is correct |
27 |
Correct |
14 ms |
25940 KB |
Output is correct |
28 |
Correct |
355 ms |
72552 KB |
Output is correct |
29 |
Correct |
545 ms |
103456 KB |
Output is correct |
30 |
Correct |
769 ms |
147020 KB |
Output is correct |
31 |
Correct |
849 ms |
146164 KB |
Output is correct |
32 |
Correct |
411 ms |
82408 KB |
Output is correct |
33 |
Correct |
833 ms |
149320 KB |
Output is correct |
34 |
Correct |
798 ms |
149352 KB |
Output is correct |
35 |
Correct |
197 ms |
63928 KB |
Output is correct |
36 |
Correct |
730 ms |
131336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
61 ms |
62148 KB |
Output is correct |
2 |
Correct |
61 ms |
62152 KB |
Output is correct |
3 |
Correct |
100 ms |
62668 KB |
Output is correct |
4 |
Correct |
92 ms |
64952 KB |
Output is correct |
5 |
Correct |
127 ms |
70788 KB |
Output is correct |
6 |
Correct |
130 ms |
70092 KB |
Output is correct |
7 |
Correct |
136 ms |
70732 KB |
Output is correct |
8 |
Correct |
133 ms |
70732 KB |
Output is correct |
9 |
Correct |
187 ms |
98840 KB |
Output is correct |
10 |
Correct |
120 ms |
55244 KB |
Output is correct |
11 |
Correct |
230 ms |
86140 KB |
Output is correct |
12 |
Correct |
13 ms |
23708 KB |
Output is correct |
13 |
Correct |
13 ms |
23816 KB |
Output is correct |
14 |
Correct |
10 ms |
23764 KB |
Output is correct |
15 |
Correct |
11 ms |
23924 KB |
Output is correct |
16 |
Correct |
12 ms |
23776 KB |
Output is correct |
17 |
Correct |
10 ms |
23764 KB |
Output is correct |
18 |
Correct |
63 ms |
62152 KB |
Output is correct |
19 |
Correct |
59 ms |
62152 KB |
Output is correct |
20 |
Correct |
67 ms |
62152 KB |
Output is correct |
21 |
Correct |
63 ms |
62028 KB |
Output is correct |
22 |
Correct |
245 ms |
102520 KB |
Output is correct |
23 |
Correct |
331 ms |
118284 KB |
Output is correct |
24 |
Correct |
345 ms |
122448 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
159 ms |
82388 KB |
Output is correct |
2 |
Correct |
196 ms |
92104 KB |
Output is correct |
3 |
Correct |
65 ms |
62028 KB |
Output is correct |
4 |
Correct |
62 ms |
62028 KB |
Output is correct |
5 |
Correct |
818 ms |
184732 KB |
Output is correct |
6 |
Correct |
623 ms |
185568 KB |
Output is correct |
7 |
Correct |
10 ms |
23764 KB |
Output is correct |
8 |
Correct |
307 ms |
100288 KB |
Output is correct |
9 |
Correct |
385 ms |
111172 KB |
Output is correct |
10 |
Correct |
163 ms |
82484 KB |
Output is correct |
11 |
Correct |
193 ms |
92104 KB |
Output is correct |
12 |
Correct |
11 ms |
23764 KB |
Output is correct |
13 |
Correct |
10 ms |
23764 KB |
Output is correct |
14 |
Correct |
10 ms |
23764 KB |
Output is correct |
15 |
Correct |
11 ms |
23892 KB |
Output is correct |
16 |
Correct |
60 ms |
62028 KB |
Output is correct |
17 |
Correct |
60 ms |
62148 KB |
Output is correct |
18 |
Correct |
217 ms |
92208 KB |
Output is correct |
19 |
Correct |
278 ms |
103872 KB |
Output is correct |
20 |
Correct |
210 ms |
87260 KB |
Output is correct |
21 |
Correct |
200 ms |
85452 KB |
Output is correct |
22 |
Correct |
213 ms |
87348 KB |
Output is correct |
23 |
Correct |
244 ms |
94372 KB |
Output is correct |
24 |
Correct |
61 ms |
62148 KB |
Output is correct |
25 |
Correct |
61 ms |
62152 KB |
Output is correct |
26 |
Correct |
100 ms |
62668 KB |
Output is correct |
27 |
Correct |
92 ms |
64952 KB |
Output is correct |
28 |
Correct |
127 ms |
70788 KB |
Output is correct |
29 |
Correct |
130 ms |
70092 KB |
Output is correct |
30 |
Correct |
136 ms |
70732 KB |
Output is correct |
31 |
Correct |
133 ms |
70732 KB |
Output is correct |
32 |
Correct |
12 ms |
23892 KB |
Output is correct |
33 |
Correct |
10 ms |
23764 KB |
Output is correct |
34 |
Correct |
12 ms |
23820 KB |
Output is correct |
35 |
Correct |
12 ms |
23764 KB |
Output is correct |
36 |
Correct |
11 ms |
23764 KB |
Output is correct |
37 |
Correct |
11 ms |
23764 KB |
Output is correct |
38 |
Correct |
10 ms |
23764 KB |
Output is correct |
39 |
Correct |
14 ms |
23980 KB |
Output is correct |
40 |
Correct |
10 ms |
23892 KB |
Output is correct |
41 |
Correct |
12 ms |
24276 KB |
Output is correct |
42 |
Correct |
14 ms |
24020 KB |
Output is correct |
43 |
Correct |
11 ms |
24148 KB |
Output is correct |
44 |
Correct |
10 ms |
23796 KB |
Output is correct |
45 |
Correct |
10 ms |
24020 KB |
Output is correct |
46 |
Correct |
11 ms |
24020 KB |
Output is correct |
47 |
Correct |
13 ms |
24276 KB |
Output is correct |
48 |
Correct |
68 ms |
34892 KB |
Output is correct |
49 |
Correct |
61 ms |
33740 KB |
Output is correct |
50 |
Correct |
61 ms |
33876 KB |
Output is correct |
51 |
Correct |
57 ms |
32972 KB |
Output is correct |
52 |
Correct |
63 ms |
33004 KB |
Output is correct |
53 |
Correct |
113 ms |
41916 KB |
Output is correct |
54 |
Correct |
28 ms |
27476 KB |
Output is correct |
55 |
Correct |
61 ms |
33868 KB |
Output is correct |
56 |
Correct |
13 ms |
24276 KB |
Output is correct |
57 |
Correct |
29 ms |
26964 KB |
Output is correct |
58 |
Correct |
14 ms |
25940 KB |
Output is correct |
59 |
Correct |
355 ms |
72552 KB |
Output is correct |
60 |
Correct |
545 ms |
103456 KB |
Output is correct |
61 |
Correct |
769 ms |
147020 KB |
Output is correct |
62 |
Correct |
849 ms |
146164 KB |
Output is correct |
63 |
Correct |
411 ms |
82408 KB |
Output is correct |
64 |
Correct |
833 ms |
149320 KB |
Output is correct |
65 |
Correct |
798 ms |
149352 KB |
Output is correct |
66 |
Correct |
197 ms |
63928 KB |
Output is correct |
67 |
Correct |
730 ms |
131336 KB |
Output is correct |
68 |
Correct |
187 ms |
98840 KB |
Output is correct |
69 |
Correct |
120 ms |
55244 KB |
Output is correct |
70 |
Correct |
230 ms |
86140 KB |
Output is correct |
71 |
Correct |
13 ms |
23708 KB |
Output is correct |
72 |
Correct |
13 ms |
23816 KB |
Output is correct |
73 |
Correct |
10 ms |
23764 KB |
Output is correct |
74 |
Correct |
11 ms |
23924 KB |
Output is correct |
75 |
Correct |
12 ms |
23776 KB |
Output is correct |
76 |
Correct |
10 ms |
23764 KB |
Output is correct |
77 |
Correct |
63 ms |
62152 KB |
Output is correct |
78 |
Correct |
59 ms |
62152 KB |
Output is correct |
79 |
Correct |
67 ms |
62152 KB |
Output is correct |
80 |
Correct |
63 ms |
62028 KB |
Output is correct |
81 |
Correct |
245 ms |
102520 KB |
Output is correct |
82 |
Correct |
331 ms |
118284 KB |
Output is correct |
83 |
Correct |
345 ms |
122448 KB |
Output is correct |
84 |
Correct |
914 ms |
168292 KB |
Output is correct |
85 |
Correct |
899 ms |
171280 KB |
Output is correct |
86 |
Correct |
645 ms |
181448 KB |
Output is correct |
87 |
Correct |
600 ms |
186272 KB |
Output is correct |
88 |
Correct |
10 ms |
23764 KB |
Output is correct |
89 |
Correct |
600 ms |
186120 KB |
Output is correct |
90 |
Correct |
515 ms |
157316 KB |
Output is correct |
91 |
Correct |
405 ms |
128724 KB |
Output is correct |