#include "fish.h"
//include "grader.cpp"
#include <bits/stdc++.h>
using namespace std;
#define int long long
map<pair<int, pair<bool, bool>>, int> memo;
vector<int> values;
int n;
int dp(int empl, bool take, bool pretake) {
if (empl>=n) return 0;
if (memo.count({empl, {take, pretake}})) return memo[{empl, {take, pretake}}];
int ans=dp(empl+1, false, take);
int temp=dp(empl+1, true, take);
if (!pretake && !take && empl>0) {
temp+=values[empl-1];
}
if (empl+1<n) temp+=values[empl+1];
if (take) temp-=values[empl];
return memo[{empl, {take, pretake}}]=max(ans, temp);
}
#undef int
long long max_weights(int N, int m, vector<int> x, vector<int> y, vector<int> w) {
#define int long long
n=N;
bool tacha=true, tachb=true, tachc=true;
for (int i = 0; i < m; ++i)
{
if (x[i]%2) tacha=false;
if (x[i]>1) tachb=false;
if (y[i]) tachc=false;
}
if (tacha)
{
int ans=0;
for (int i = 0; i < m; ++i) ans+=w[i];
return ans;
}
if (tachb)
{
vector<vector<int>> farm(2, vector<int> (n, 0));
for (int i=0; i<m; i++) {
farm[x[i]][y[i]]=w[i];
}
vector<int> suml, sumr;
suml.push_back(farm[0][0]);
sumr.push_back(farm[1][0]);
for (int i=1; i<n; i++) {
suml.push_back(suml.back()+farm[0][i]);
sumr.push_back(sumr.back()+farm[1][i]);
}
if (n==2) return max(suml.back(), sumr.back());
int ans=sumr.back();
for (int i=0; i<n; i++) {
ans=max(ans, suml[i]+sumr.back()-sumr[i]);
}
return ans;
}
values.resize(n);
for (int i=0; i<m; i++) {
values[x[i]]=w[i];
}
return dp(0, false, false);
#undef int
}
Compilation message
fish.cpp: In function 'long long int max_weights(int, int, std::vector<int>, std::vector<int>, std::vector<int>)':
fish.cpp:29:31: warning: variable 'tachc' set but not used [-Wunused-but-set-variable]
29 | bool tacha=true, tachb=true, tachc=true;
| ^~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
2140 KB |
Output is correct |
2 |
Correct |
21 ms |
2904 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
68 ms |
7268 KB |
Output is correct |
6 |
Correct |
72 ms |
7288 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
600 KB |
Output is correct |
2 |
Correct |
45 ms |
8032 KB |
Output is correct |
3 |
Correct |
50 ms |
9416 KB |
Output is correct |
4 |
Correct |
18 ms |
2132 KB |
Output is correct |
5 |
Correct |
22 ms |
2640 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
500 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 |
22 ms |
6076 KB |
Output is correct |
13 |
Correct |
25 ms |
7104 KB |
Output is correct |
14 |
Correct |
27 ms |
6072 KB |
Output is correct |
15 |
Correct |
23 ms |
6872 KB |
Output is correct |
16 |
Correct |
20 ms |
6040 KB |
Output is correct |
17 |
Correct |
22 ms |
6988 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
177 ms |
38736 KB |
Output is correct |
3 |
Correct |
170 ms |
36996 KB |
Output is correct |
4 |
Correct |
197 ms |
40272 KB |
Output is correct |
5 |
Correct |
199 ms |
42580 KB |
Output is correct |
6 |
Correct |
195 ms |
42064 KB |
Output is correct |
7 |
Correct |
207 ms |
42832 KB |
Output is correct |
8 |
Correct |
197 ms |
42672 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
1st lines differ - on the 1st token, expected: '3', found: '2' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
1st lines differ - on the 1st token, expected: '3', found: '2' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
1st lines differ - on the 1st token, expected: '3', found: '2' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
177 ms |
38736 KB |
Output is correct |
3 |
Correct |
170 ms |
36996 KB |
Output is correct |
4 |
Correct |
197 ms |
40272 KB |
Output is correct |
5 |
Correct |
199 ms |
42580 KB |
Output is correct |
6 |
Correct |
195 ms |
42064 KB |
Output is correct |
7 |
Correct |
207 ms |
42832 KB |
Output is correct |
8 |
Correct |
197 ms |
42672 KB |
Output is correct |
9 |
Incorrect |
200 ms |
42324 KB |
1st lines differ - on the 1st token, expected: '99999', found: '66666' |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
2140 KB |
Output is correct |
2 |
Correct |
21 ms |
2904 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
68 ms |
7268 KB |
Output is correct |
6 |
Correct |
72 ms |
7288 KB |
Output is correct |
7 |
Correct |
0 ms |
600 KB |
Output is correct |
8 |
Correct |
45 ms |
8032 KB |
Output is correct |
9 |
Correct |
50 ms |
9416 KB |
Output is correct |
10 |
Correct |
18 ms |
2132 KB |
Output is correct |
11 |
Correct |
22 ms |
2640 KB |
Output is correct |
12 |
Correct |
0 ms |
344 KB |
Output is correct |
13 |
Correct |
1 ms |
500 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 |
22 ms |
6076 KB |
Output is correct |
19 |
Correct |
25 ms |
7104 KB |
Output is correct |
20 |
Correct |
27 ms |
6072 KB |
Output is correct |
21 |
Correct |
23 ms |
6872 KB |
Output is correct |
22 |
Correct |
20 ms |
6040 KB |
Output is correct |
23 |
Correct |
22 ms |
6988 KB |
Output is correct |
24 |
Correct |
0 ms |
344 KB |
Output is correct |
25 |
Correct |
177 ms |
38736 KB |
Output is correct |
26 |
Correct |
170 ms |
36996 KB |
Output is correct |
27 |
Correct |
197 ms |
40272 KB |
Output is correct |
28 |
Correct |
199 ms |
42580 KB |
Output is correct |
29 |
Correct |
195 ms |
42064 KB |
Output is correct |
30 |
Correct |
207 ms |
42832 KB |
Output is correct |
31 |
Correct |
197 ms |
42672 KB |
Output is correct |
32 |
Incorrect |
0 ms |
348 KB |
1st lines differ - on the 1st token, expected: '3', found: '2' |
33 |
Halted |
0 ms |
0 KB |
- |