#include "fish.h"
#include <bits/stdc++.h>
#define MAX 100001
#define INF LLONG_MAX
#define MOD 1000000007
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define ins insert
#define ff first
#define ss second
#define gett(x,m) get<m>(x)
#define all(a) a.begin(),a.end()
#define lb(a,b) lower_bound(all(a),b)
#define ub(a,b) upper_bound(all(a),b)
#define sortv(a) sort(all(a))
#define sorta(a,sz) sort(a,a+sz)
#define inputar(a,b){\
for(int i=0;i<b;i++){\
cin >> a[i];\
}\
}
#define inputvec(a,b){\
for(int i=0;i<b;i++){\
ll num;\
cin >> num;\
a.pb(num);\
}\
}
#define outputar(a,b){\
for(int i=0;i<b;i++){\
cout << a[i] << " ";\
}\
cout << "\n";\
}
#define outputvec(a){\
for(auto x:a){\
cout << x << " ";\
}\
cout << "\n";\
}
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef tuple<ll,ll,ll> tll;
typedef pair<ll,ll> pll;
typedef double db;
typedef long double ldb;
ll n,q,t=1,m,n2,m2,k,cnt=0,a[MAX],b[MAX],d[MAX],d2[MAX],x,y,z,x2,y2,z2,res1=0,cnt1,cnt2,cnt3;
ll dp[3001][3001][2];
ll dp2[3001][3001];
ll arr[3001][3001];
long long max_weights(int N, int M, vector<int> X, vector<int> Y, vector<int> W){
bool ok=false;
bool ok2=false;
bool ok3=false;
for(int i=0;i<M;i++){
if(X[i]%2){
ok=true;
}
if(Y[i]!=0){
ok2=true;
}
if(X[i]>1){
ok3=true;
}
a[X[i]]=W[i];
if(X[i]==0){
b[Y[i]]=W[i];
}
else{
d[Y[i]]=W[i];
}
}
if(!ok){
ll res=0;
for(int i=0;i<M;i++){
res+=W[i];
}
return res;
}
if(!ok2){
ll res=0;
ll dp[N][2];
dp[0][0]=dp[0][1]=0;
dp[1][0]=a[1];
dp[1][1]=a[0];
for(int i=2;i<N;i++){
dp[i][0]=dp[i-1][0];
dp[i][1]=dp[i-1][1];
dp[i][0]=max(dp[i][0],dp[i-1][1]+a[i]);
dp[i][1]=max(dp[i][1],max(dp[i-2][0],dp[i-2][1])+a[i-1]);
}
return max(dp[N-1][0],dp[N-1][1]);
}
if(!ok3){
for(int i=1;i<N;i++){
b[i]+=b[i-1];
d[i]+=d[i-1];
}
ll res=max(b[N-1],d[N-1]);
if(N>2){
for(int i=0;i<N;i++){
res=max(res,b[i]+d[N-1]-d[i]);
}
}
return res;
}
for(int i=0;i<M;i++){
arr[X[i]+1][Y[i]+1]=W[i];
}
for(int i=2;i<=N;i++){
ll res2=0;
for(int j=N;j>=0;j--){
res2=max(res2,max(dp[i-1][j][0],dp[i-1][j][1]));
dp[i][j][1]=res2;
res2+=arr[i][j];
}
res2=0;
for(int j=0;j<=N;j++){
res2=max(res2,dp[i-1][j][1]);
dp[i][j][0]=res2;
}
res2=0;
for(int j=0;j<=N;j++){
res2=max(res2+arr[i-1][j],dp[i-1][j][0]);
dp[i][j][0]=max(dp[i][j][0],res2);
}
}
ll res=0;
for(int i=1;i<=N;i++){
for(int j=0;j<=N;j++){
res=max(res,max(dp[i][j][0],dp[i][j][1]));
}
}
return res;
}
Compilation message
fish.cpp: In function 'long long int max_weights(int, int, std::vector<int>, std::vector<int>, std::vector<int>)':
fish.cpp:83:12: warning: unused variable 'res' [-Wunused-variable]
83 | ll res=0;
| ^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
23 ms |
2896 KB |
Output is correct |
2 |
Correct |
28 ms |
3396 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
93 ms |
8060 KB |
Output is correct |
6 |
Correct |
96 ms |
8808 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
61 ms |
5544 KB |
Output is correct |
3 |
Correct |
59 ms |
6492 KB |
Output is correct |
4 |
Correct |
25 ms |
2796 KB |
Output is correct |
5 |
Correct |
41 ms |
3532 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
312 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
304 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
24 ms |
4964 KB |
Output is correct |
13 |
Correct |
28 ms |
5948 KB |
Output is correct |
14 |
Correct |
28 ms |
4968 KB |
Output is correct |
15 |
Correct |
28 ms |
5588 KB |
Output is correct |
16 |
Correct |
27 ms |
4948 KB |
Output is correct |
17 |
Correct |
28 ms |
5540 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
2 ms |
1876 KB |
Output is correct |
3 |
Correct |
16 ms |
3636 KB |
Output is correct |
4 |
Correct |
22 ms |
3164 KB |
Output is correct |
5 |
Correct |
31 ms |
4924 KB |
Output is correct |
6 |
Correct |
21 ms |
4940 KB |
Output is correct |
7 |
Correct |
31 ms |
4940 KB |
Output is correct |
8 |
Correct |
28 ms |
5024 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
308 KB |
Output is correct |
7 |
Correct |
1 ms |
304 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
2 ms |
1876 KB |
Output is correct |
10 |
Correct |
3 ms |
4180 KB |
Output is correct |
11 |
Correct |
2 ms |
1876 KB |
Output is correct |
12 |
Correct |
4 ms |
4180 KB |
Output is correct |
13 |
Correct |
1 ms |
944 KB |
Output is correct |
14 |
Correct |
4 ms |
4180 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
308 KB |
Output is correct |
7 |
Correct |
1 ms |
304 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
2 ms |
1876 KB |
Output is correct |
10 |
Correct |
3 ms |
4180 KB |
Output is correct |
11 |
Correct |
2 ms |
1876 KB |
Output is correct |
12 |
Correct |
4 ms |
4180 KB |
Output is correct |
13 |
Correct |
1 ms |
944 KB |
Output is correct |
14 |
Correct |
4 ms |
4180 KB |
Output is correct |
15 |
Correct |
3 ms |
4180 KB |
Output is correct |
16 |
Correct |
2 ms |
852 KB |
Output is correct |
17 |
Correct |
20 ms |
5952 KB |
Output is correct |
18 |
Correct |
15 ms |
5820 KB |
Output is correct |
19 |
Correct |
21 ms |
6316 KB |
Output is correct |
20 |
Correct |
21 ms |
6204 KB |
Output is correct |
21 |
Correct |
16 ms |
6208 KB |
Output is correct |
22 |
Correct |
30 ms |
8396 KB |
Output is correct |
23 |
Correct |
6 ms |
5168 KB |
Output is correct |
24 |
Correct |
12 ms |
6016 KB |
Output is correct |
25 |
Correct |
3 ms |
4180 KB |
Output is correct |
26 |
Correct |
5 ms |
4792 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
308 KB |
Output is correct |
7 |
Correct |
1 ms |
304 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
2 ms |
1876 KB |
Output is correct |
10 |
Correct |
3 ms |
4180 KB |
Output is correct |
11 |
Correct |
2 ms |
1876 KB |
Output is correct |
12 |
Correct |
4 ms |
4180 KB |
Output is correct |
13 |
Correct |
1 ms |
944 KB |
Output is correct |
14 |
Correct |
4 ms |
4180 KB |
Output is correct |
15 |
Correct |
3 ms |
4180 KB |
Output is correct |
16 |
Correct |
2 ms |
852 KB |
Output is correct |
17 |
Correct |
20 ms |
5952 KB |
Output is correct |
18 |
Correct |
15 ms |
5820 KB |
Output is correct |
19 |
Correct |
21 ms |
6316 KB |
Output is correct |
20 |
Correct |
21 ms |
6204 KB |
Output is correct |
21 |
Correct |
16 ms |
6208 KB |
Output is correct |
22 |
Correct |
30 ms |
8396 KB |
Output is correct |
23 |
Correct |
6 ms |
5168 KB |
Output is correct |
24 |
Correct |
12 ms |
6016 KB |
Output is correct |
25 |
Correct |
3 ms |
4180 KB |
Output is correct |
26 |
Correct |
5 ms |
4792 KB |
Output is correct |
27 |
Correct |
117 ms |
153380 KB |
Output is correct |
28 |
Correct |
75 ms |
24452 KB |
Output is correct |
29 |
Correct |
202 ms |
157148 KB |
Output is correct |
30 |
Correct |
200 ms |
199924 KB |
Output is correct |
31 |
Correct |
195 ms |
200524 KB |
Output is correct |
32 |
Correct |
96 ms |
24036 KB |
Output is correct |
33 |
Correct |
205 ms |
224356 KB |
Output is correct |
34 |
Correct |
209 ms |
224340 KB |
Output is correct |
35 |
Correct |
154 ms |
161112 KB |
Output is correct |
36 |
Correct |
194 ms |
170192 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
2 ms |
1876 KB |
Output is correct |
3 |
Correct |
16 ms |
3636 KB |
Output is correct |
4 |
Correct |
22 ms |
3164 KB |
Output is correct |
5 |
Correct |
31 ms |
4924 KB |
Output is correct |
6 |
Correct |
21 ms |
4940 KB |
Output is correct |
7 |
Correct |
31 ms |
4940 KB |
Output is correct |
8 |
Correct |
28 ms |
5024 KB |
Output is correct |
9 |
Runtime error |
32 ms |
8264 KB |
Execution killed with signal 11 |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
23 ms |
2896 KB |
Output is correct |
2 |
Correct |
28 ms |
3396 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
93 ms |
8060 KB |
Output is correct |
6 |
Correct |
96 ms |
8808 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
61 ms |
5544 KB |
Output is correct |
9 |
Correct |
59 ms |
6492 KB |
Output is correct |
10 |
Correct |
25 ms |
2796 KB |
Output is correct |
11 |
Correct |
41 ms |
3532 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
312 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
304 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
24 ms |
4964 KB |
Output is correct |
19 |
Correct |
28 ms |
5948 KB |
Output is correct |
20 |
Correct |
28 ms |
4968 KB |
Output is correct |
21 |
Correct |
28 ms |
5588 KB |
Output is correct |
22 |
Correct |
27 ms |
4948 KB |
Output is correct |
23 |
Correct |
28 ms |
5540 KB |
Output is correct |
24 |
Correct |
1 ms |
212 KB |
Output is correct |
25 |
Correct |
2 ms |
1876 KB |
Output is correct |
26 |
Correct |
16 ms |
3636 KB |
Output is correct |
27 |
Correct |
22 ms |
3164 KB |
Output is correct |
28 |
Correct |
31 ms |
4924 KB |
Output is correct |
29 |
Correct |
21 ms |
4940 KB |
Output is correct |
30 |
Correct |
31 ms |
4940 KB |
Output is correct |
31 |
Correct |
28 ms |
5024 KB |
Output is correct |
32 |
Correct |
1 ms |
340 KB |
Output is correct |
33 |
Correct |
1 ms |
340 KB |
Output is correct |
34 |
Correct |
1 ms |
212 KB |
Output is correct |
35 |
Correct |
1 ms |
212 KB |
Output is correct |
36 |
Correct |
1 ms |
212 KB |
Output is correct |
37 |
Correct |
1 ms |
308 KB |
Output is correct |
38 |
Correct |
1 ms |
304 KB |
Output is correct |
39 |
Correct |
1 ms |
340 KB |
Output is correct |
40 |
Correct |
2 ms |
1876 KB |
Output is correct |
41 |
Correct |
3 ms |
4180 KB |
Output is correct |
42 |
Correct |
2 ms |
1876 KB |
Output is correct |
43 |
Correct |
4 ms |
4180 KB |
Output is correct |
44 |
Correct |
1 ms |
944 KB |
Output is correct |
45 |
Correct |
4 ms |
4180 KB |
Output is correct |
46 |
Correct |
3 ms |
4180 KB |
Output is correct |
47 |
Correct |
2 ms |
852 KB |
Output is correct |
48 |
Correct |
20 ms |
5952 KB |
Output is correct |
49 |
Correct |
15 ms |
5820 KB |
Output is correct |
50 |
Correct |
21 ms |
6316 KB |
Output is correct |
51 |
Correct |
21 ms |
6204 KB |
Output is correct |
52 |
Correct |
16 ms |
6208 KB |
Output is correct |
53 |
Correct |
30 ms |
8396 KB |
Output is correct |
54 |
Correct |
6 ms |
5168 KB |
Output is correct |
55 |
Correct |
12 ms |
6016 KB |
Output is correct |
56 |
Correct |
3 ms |
4180 KB |
Output is correct |
57 |
Correct |
5 ms |
4792 KB |
Output is correct |
58 |
Correct |
117 ms |
153380 KB |
Output is correct |
59 |
Correct |
75 ms |
24452 KB |
Output is correct |
60 |
Correct |
202 ms |
157148 KB |
Output is correct |
61 |
Correct |
200 ms |
199924 KB |
Output is correct |
62 |
Correct |
195 ms |
200524 KB |
Output is correct |
63 |
Correct |
96 ms |
24036 KB |
Output is correct |
64 |
Correct |
205 ms |
224356 KB |
Output is correct |
65 |
Correct |
209 ms |
224340 KB |
Output is correct |
66 |
Correct |
154 ms |
161112 KB |
Output is correct |
67 |
Correct |
194 ms |
170192 KB |
Output is correct |
68 |
Runtime error |
32 ms |
8264 KB |
Execution killed with signal 11 |
69 |
Halted |
0 ms |
0 KB |
- |