#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[301][301][301]; // normal dp
ll dp2[301][301][301]; // max from 0 to x
ll dp3[301][301][301]; // max from x to N
ll dp4[301][301][301]; // max from x to y
ll dp5[301][301];
ll arr[301][301];
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=0;i<=N;i++){
for(int j=1;j<=N;j++){
arr[i][j]+=arr[i][j-1];
}
}
for(int i=2;i<=N;i++){
for(int j=0;j<=N;j++){
for(int z=j;z<=N;z++){
dp[i][j][z]=dp5[i-1][z]+arr[i][z]-arr[i][j];
dp5[i][j]=max(dp[i][j][z],dp5[i][j]);
}
for(int z=0;z<j;z++){
ll res2=dp4[i-1][z][j]+arr[i-1][j]-arr[i-1][z];
if(z-1>=0){
res2=max(res2,dp2[i-1][z][z-1]+arr[i-1][j]-arr[i-1][z]);
}
if(j+1<=N){
res2=max(res2,dp3[i-1][z][j+1]);
}
dp[i][j][z]=max(dp[i][j][z],res2);
dp5[i][j]=max(dp5[i][j],dp[i][j][z]);
}
}
for(int j=0;j<=N;j++){
for(int z=0;z<=N;z++){
dp2[i][j][z]=dp[i][j][z];
dp3[i][j][z]=dp[i][j][z];
}
ll mx=0;
for(int z=j;z<=N;z++){
mx=max(mx,dp[i][j][z]-(arr[i][z]-arr[i][j]));
dp4[i][j][z]=mx;
}
}
for(int j=0;j<=N;j++){
for(int z=1;z<=N;z++){
dp2[i][j][z]=max(dp2[i][j][z],dp2[i][j][z-1]);
}
for(int z=N-1;z>=0;z--){
dp3[i][j][z]=max(dp3[i][j][z],dp3[i][j][z+1]);
}
}
}
ll res=0;
for(int i=0;i<=N;i++){
res=max(res,dp5[N][i]);
}
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:86:12: warning: unused variable 'res' [-Wunused-variable]
86 | ll res=0;
| ^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
26 ms |
4044 KB |
Output is correct |
2 |
Correct |
41 ms |
4560 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
89 ms |
9064 KB |
Output is correct |
6 |
Correct |
91 ms |
9928 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
65 ms |
6572 KB |
Output is correct |
3 |
Correct |
74 ms |
7628 KB |
Output is correct |
4 |
Correct |
24 ms |
3940 KB |
Output is correct |
5 |
Correct |
31 ms |
4584 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
300 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
308 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
25 ms |
4720 KB |
Output is correct |
13 |
Correct |
34 ms |
5308 KB |
Output is correct |
14 |
Correct |
27 ms |
4752 KB |
Output is correct |
15 |
Correct |
30 ms |
5080 KB |
Output is correct |
16 |
Correct |
28 ms |
4768 KB |
Output is correct |
17 |
Correct |
28 ms |
5052 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
2 ms |
1876 KB |
Output is correct |
3 |
Correct |
17 ms |
4508 KB |
Output is correct |
4 |
Correct |
12 ms |
3772 KB |
Output is correct |
5 |
Correct |
32 ms |
6092 KB |
Output is correct |
6 |
Correct |
24 ms |
5948 KB |
Output is correct |
7 |
Correct |
37 ms |
6080 KB |
Output is correct |
8 |
Correct |
30 ms |
6048 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
468 KB |
Output is correct |
2 |
Correct |
1 ms |
944 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
308 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
116 ms |
215100 KB |
Output is correct |
10 |
Correct |
617 ms |
850004 KB |
Output is correct |
11 |
Correct |
113 ms |
215164 KB |
Output is correct |
12 |
Correct |
634 ms |
849988 KB |
Output is correct |
13 |
Correct |
26 ms |
54568 KB |
Output is correct |
14 |
Correct |
617 ms |
849944 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
468 KB |
Output is correct |
2 |
Correct |
1 ms |
944 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
308 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
116 ms |
215100 KB |
Output is correct |
10 |
Correct |
617 ms |
850004 KB |
Output is correct |
11 |
Correct |
113 ms |
215164 KB |
Output is correct |
12 |
Correct |
634 ms |
849988 KB |
Output is correct |
13 |
Correct |
26 ms |
54568 KB |
Output is correct |
14 |
Correct |
617 ms |
849944 KB |
Output is correct |
15 |
Correct |
639 ms |
849888 KB |
Output is correct |
16 |
Correct |
27 ms |
54624 KB |
Output is correct |
17 |
Correct |
611 ms |
851756 KB |
Output is correct |
18 |
Correct |
601 ms |
851784 KB |
Output is correct |
19 |
Correct |
617 ms |
851916 KB |
Output is correct |
20 |
Correct |
603 ms |
851776 KB |
Output is correct |
21 |
Correct |
616 ms |
851900 KB |
Output is correct |
22 |
Correct |
616 ms |
853596 KB |
Output is correct |
23 |
Correct |
602 ms |
850340 KB |
Output is correct |
24 |
Correct |
637 ms |
851112 KB |
Output is correct |
25 |
Correct |
594 ms |
850068 KB |
Output is correct |
26 |
Correct |
609 ms |
850244 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
468 KB |
Output is correct |
2 |
Correct |
1 ms |
944 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
308 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
116 ms |
215100 KB |
Output is correct |
10 |
Correct |
617 ms |
850004 KB |
Output is correct |
11 |
Correct |
113 ms |
215164 KB |
Output is correct |
12 |
Correct |
634 ms |
849988 KB |
Output is correct |
13 |
Correct |
26 ms |
54568 KB |
Output is correct |
14 |
Correct |
617 ms |
849944 KB |
Output is correct |
15 |
Correct |
639 ms |
849888 KB |
Output is correct |
16 |
Correct |
27 ms |
54624 KB |
Output is correct |
17 |
Correct |
611 ms |
851756 KB |
Output is correct |
18 |
Correct |
601 ms |
851784 KB |
Output is correct |
19 |
Correct |
617 ms |
851916 KB |
Output is correct |
20 |
Correct |
603 ms |
851776 KB |
Output is correct |
21 |
Correct |
616 ms |
851900 KB |
Output is correct |
22 |
Correct |
616 ms |
853596 KB |
Output is correct |
23 |
Correct |
602 ms |
850340 KB |
Output is correct |
24 |
Correct |
637 ms |
851112 KB |
Output is correct |
25 |
Correct |
594 ms |
850068 KB |
Output is correct |
26 |
Correct |
609 ms |
850244 KB |
Output is correct |
27 |
Execution timed out |
1060 ms |
48640 KB |
Time limit exceeded |
28 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
2 ms |
1876 KB |
Output is correct |
3 |
Correct |
17 ms |
4508 KB |
Output is correct |
4 |
Correct |
12 ms |
3772 KB |
Output is correct |
5 |
Correct |
32 ms |
6092 KB |
Output is correct |
6 |
Correct |
24 ms |
5948 KB |
Output is correct |
7 |
Correct |
37 ms |
6080 KB |
Output is correct |
8 |
Correct |
30 ms |
6048 KB |
Output is correct |
9 |
Execution timed out |
1075 ms |
241700 KB |
Time limit exceeded |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
26 ms |
4044 KB |
Output is correct |
2 |
Correct |
41 ms |
4560 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
89 ms |
9064 KB |
Output is correct |
6 |
Correct |
91 ms |
9928 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
65 ms |
6572 KB |
Output is correct |
9 |
Correct |
74 ms |
7628 KB |
Output is correct |
10 |
Correct |
24 ms |
3940 KB |
Output is correct |
11 |
Correct |
31 ms |
4584 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
300 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
308 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
25 ms |
4720 KB |
Output is correct |
19 |
Correct |
34 ms |
5308 KB |
Output is correct |
20 |
Correct |
27 ms |
4752 KB |
Output is correct |
21 |
Correct |
30 ms |
5080 KB |
Output is correct |
22 |
Correct |
28 ms |
4768 KB |
Output is correct |
23 |
Correct |
28 ms |
5052 KB |
Output is correct |
24 |
Correct |
1 ms |
212 KB |
Output is correct |
25 |
Correct |
2 ms |
1876 KB |
Output is correct |
26 |
Correct |
17 ms |
4508 KB |
Output is correct |
27 |
Correct |
12 ms |
3772 KB |
Output is correct |
28 |
Correct |
32 ms |
6092 KB |
Output is correct |
29 |
Correct |
24 ms |
5948 KB |
Output is correct |
30 |
Correct |
37 ms |
6080 KB |
Output is correct |
31 |
Correct |
30 ms |
6048 KB |
Output is correct |
32 |
Correct |
1 ms |
468 KB |
Output is correct |
33 |
Correct |
1 ms |
944 KB |
Output is correct |
34 |
Correct |
1 ms |
212 KB |
Output is correct |
35 |
Correct |
1 ms |
308 KB |
Output is correct |
36 |
Correct |
1 ms |
212 KB |
Output is correct |
37 |
Correct |
1 ms |
212 KB |
Output is correct |
38 |
Correct |
1 ms |
212 KB |
Output is correct |
39 |
Correct |
1 ms |
340 KB |
Output is correct |
40 |
Correct |
116 ms |
215100 KB |
Output is correct |
41 |
Correct |
617 ms |
850004 KB |
Output is correct |
42 |
Correct |
113 ms |
215164 KB |
Output is correct |
43 |
Correct |
634 ms |
849988 KB |
Output is correct |
44 |
Correct |
26 ms |
54568 KB |
Output is correct |
45 |
Correct |
617 ms |
849944 KB |
Output is correct |
46 |
Correct |
639 ms |
849888 KB |
Output is correct |
47 |
Correct |
27 ms |
54624 KB |
Output is correct |
48 |
Correct |
611 ms |
851756 KB |
Output is correct |
49 |
Correct |
601 ms |
851784 KB |
Output is correct |
50 |
Correct |
617 ms |
851916 KB |
Output is correct |
51 |
Correct |
603 ms |
851776 KB |
Output is correct |
52 |
Correct |
616 ms |
851900 KB |
Output is correct |
53 |
Correct |
616 ms |
853596 KB |
Output is correct |
54 |
Correct |
602 ms |
850340 KB |
Output is correct |
55 |
Correct |
637 ms |
851112 KB |
Output is correct |
56 |
Correct |
594 ms |
850068 KB |
Output is correct |
57 |
Correct |
609 ms |
850244 KB |
Output is correct |
58 |
Execution timed out |
1060 ms |
48640 KB |
Time limit exceeded |
59 |
Halted |
0 ms |
0 KB |
- |