#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;
| ^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
22 ms |
2900 KB |
Output is correct |
2 |
Correct |
31 ms |
3400 KB |
Output is correct |
3 |
Correct |
0 ms |
256 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
84 ms |
8044 KB |
Output is correct |
6 |
Correct |
87 ms |
8920 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
46 ms |
5536 KB |
Output is correct |
3 |
Correct |
57 ms |
6504 KB |
Output is correct |
4 |
Correct |
22 ms |
3028 KB |
Output is correct |
5 |
Correct |
27 ms |
3416 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
23 ms |
3568 KB |
Output is correct |
13 |
Correct |
27 ms |
4124 KB |
Output is correct |
14 |
Correct |
23 ms |
3540 KB |
Output is correct |
15 |
Correct |
26 ms |
3924 KB |
Output is correct |
16 |
Correct |
24 ms |
3536 KB |
Output is correct |
17 |
Correct |
27 ms |
3936 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
2 ms |
1748 KB |
Output is correct |
3 |
Correct |
16 ms |
3708 KB |
Output is correct |
4 |
Correct |
11 ms |
3156 KB |
Output is correct |
5 |
Correct |
26 ms |
4948 KB |
Output is correct |
6 |
Correct |
22 ms |
4948 KB |
Output is correct |
7 |
Correct |
27 ms |
4936 KB |
Output is correct |
8 |
Correct |
26 ms |
4936 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
1876 KB |
Output is correct |
10 |
Correct |
3 ms |
4180 KB |
Output is correct |
11 |
Correct |
1 ms |
1876 KB |
Output is correct |
12 |
Correct |
4 ms |
4180 KB |
Output is correct |
13 |
Correct |
1 ms |
980 KB |
Output is correct |
14 |
Correct |
3 ms |
4052 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
1876 KB |
Output is correct |
10 |
Correct |
3 ms |
4180 KB |
Output is correct |
11 |
Correct |
1 ms |
1876 KB |
Output is correct |
12 |
Correct |
4 ms |
4180 KB |
Output is correct |
13 |
Correct |
1 ms |
980 KB |
Output is correct |
14 |
Correct |
3 ms |
4052 KB |
Output is correct |
15 |
Correct |
3 ms |
4052 KB |
Output is correct |
16 |
Correct |
1 ms |
852 KB |
Output is correct |
17 |
Correct |
19 ms |
5204 KB |
Output is correct |
18 |
Correct |
15 ms |
5072 KB |
Output is correct |
19 |
Correct |
15 ms |
5456 KB |
Output is correct |
20 |
Correct |
14 ms |
5580 KB |
Output is correct |
21 |
Correct |
15 ms |
5460 KB |
Output is correct |
22 |
Correct |
26 ms |
6856 KB |
Output is correct |
23 |
Correct |
5 ms |
4948 KB |
Output is correct |
24 |
Correct |
13 ms |
5460 KB |
Output is correct |
25 |
Correct |
3 ms |
4180 KB |
Output is correct |
26 |
Correct |
5 ms |
4628 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
1876 KB |
Output is correct |
10 |
Correct |
3 ms |
4180 KB |
Output is correct |
11 |
Correct |
1 ms |
1876 KB |
Output is correct |
12 |
Correct |
4 ms |
4180 KB |
Output is correct |
13 |
Correct |
1 ms |
980 KB |
Output is correct |
14 |
Correct |
3 ms |
4052 KB |
Output is correct |
15 |
Correct |
3 ms |
4052 KB |
Output is correct |
16 |
Correct |
1 ms |
852 KB |
Output is correct |
17 |
Correct |
19 ms |
5204 KB |
Output is correct |
18 |
Correct |
15 ms |
5072 KB |
Output is correct |
19 |
Correct |
15 ms |
5456 KB |
Output is correct |
20 |
Correct |
14 ms |
5580 KB |
Output is correct |
21 |
Correct |
15 ms |
5460 KB |
Output is correct |
22 |
Correct |
26 ms |
6856 KB |
Output is correct |
23 |
Correct |
5 ms |
4948 KB |
Output is correct |
24 |
Correct |
13 ms |
5460 KB |
Output is correct |
25 |
Correct |
3 ms |
4180 KB |
Output is correct |
26 |
Correct |
5 ms |
4628 KB |
Output is correct |
27 |
Correct |
111 ms |
153336 KB |
Output is correct |
28 |
Correct |
67 ms |
20748 KB |
Output is correct |
29 |
Correct |
192 ms |
151464 KB |
Output is correct |
30 |
Correct |
195 ms |
194280 KB |
Output is correct |
31 |
Correct |
198 ms |
194932 KB |
Output is correct |
32 |
Correct |
84 ms |
18808 KB |
Output is correct |
33 |
Correct |
208 ms |
218812 KB |
Output is correct |
34 |
Correct |
202 ms |
218708 KB |
Output is correct |
35 |
Correct |
145 ms |
158992 KB |
Output is correct |
36 |
Correct |
191 ms |
164684 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
2 ms |
1748 KB |
Output is correct |
3 |
Correct |
16 ms |
3708 KB |
Output is correct |
4 |
Correct |
11 ms |
3156 KB |
Output is correct |
5 |
Correct |
26 ms |
4948 KB |
Output is correct |
6 |
Correct |
22 ms |
4948 KB |
Output is correct |
7 |
Correct |
27 ms |
4936 KB |
Output is correct |
8 |
Correct |
26 ms |
4936 KB |
Output is correct |
9 |
Runtime error |
32 ms |
8272 KB |
Execution killed with signal 11 |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
22 ms |
2900 KB |
Output is correct |
2 |
Correct |
31 ms |
3400 KB |
Output is correct |
3 |
Correct |
0 ms |
256 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
84 ms |
8044 KB |
Output is correct |
6 |
Correct |
87 ms |
8920 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
46 ms |
5536 KB |
Output is correct |
9 |
Correct |
57 ms |
6504 KB |
Output is correct |
10 |
Correct |
22 ms |
3028 KB |
Output is correct |
11 |
Correct |
27 ms |
3416 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
23 ms |
3568 KB |
Output is correct |
19 |
Correct |
27 ms |
4124 KB |
Output is correct |
20 |
Correct |
23 ms |
3540 KB |
Output is correct |
21 |
Correct |
26 ms |
3924 KB |
Output is correct |
22 |
Correct |
24 ms |
3536 KB |
Output is correct |
23 |
Correct |
27 ms |
3936 KB |
Output is correct |
24 |
Correct |
0 ms |
212 KB |
Output is correct |
25 |
Correct |
2 ms |
1748 KB |
Output is correct |
26 |
Correct |
16 ms |
3708 KB |
Output is correct |
27 |
Correct |
11 ms |
3156 KB |
Output is correct |
28 |
Correct |
26 ms |
4948 KB |
Output is correct |
29 |
Correct |
22 ms |
4948 KB |
Output is correct |
30 |
Correct |
27 ms |
4936 KB |
Output is correct |
31 |
Correct |
26 ms |
4936 KB |
Output is correct |
32 |
Correct |
0 ms |
340 KB |
Output is correct |
33 |
Correct |
0 ms |
340 KB |
Output is correct |
34 |
Correct |
0 ms |
212 KB |
Output is correct |
35 |
Correct |
0 ms |
212 KB |
Output is correct |
36 |
Correct |
0 ms |
212 KB |
Output is correct |
37 |
Correct |
0 ms |
212 KB |
Output is correct |
38 |
Correct |
0 ms |
212 KB |
Output is correct |
39 |
Correct |
0 ms |
340 KB |
Output is correct |
40 |
Correct |
1 ms |
1876 KB |
Output is correct |
41 |
Correct |
3 ms |
4180 KB |
Output is correct |
42 |
Correct |
1 ms |
1876 KB |
Output is correct |
43 |
Correct |
4 ms |
4180 KB |
Output is correct |
44 |
Correct |
1 ms |
980 KB |
Output is correct |
45 |
Correct |
3 ms |
4052 KB |
Output is correct |
46 |
Correct |
3 ms |
4052 KB |
Output is correct |
47 |
Correct |
1 ms |
852 KB |
Output is correct |
48 |
Correct |
19 ms |
5204 KB |
Output is correct |
49 |
Correct |
15 ms |
5072 KB |
Output is correct |
50 |
Correct |
15 ms |
5456 KB |
Output is correct |
51 |
Correct |
14 ms |
5580 KB |
Output is correct |
52 |
Correct |
15 ms |
5460 KB |
Output is correct |
53 |
Correct |
26 ms |
6856 KB |
Output is correct |
54 |
Correct |
5 ms |
4948 KB |
Output is correct |
55 |
Correct |
13 ms |
5460 KB |
Output is correct |
56 |
Correct |
3 ms |
4180 KB |
Output is correct |
57 |
Correct |
5 ms |
4628 KB |
Output is correct |
58 |
Correct |
111 ms |
153336 KB |
Output is correct |
59 |
Correct |
67 ms |
20748 KB |
Output is correct |
60 |
Correct |
192 ms |
151464 KB |
Output is correct |
61 |
Correct |
195 ms |
194280 KB |
Output is correct |
62 |
Correct |
198 ms |
194932 KB |
Output is correct |
63 |
Correct |
84 ms |
18808 KB |
Output is correct |
64 |
Correct |
208 ms |
218812 KB |
Output is correct |
65 |
Correct |
202 ms |
218708 KB |
Output is correct |
66 |
Correct |
145 ms |
158992 KB |
Output is correct |
67 |
Correct |
191 ms |
164684 KB |
Output is correct |
68 |
Runtime error |
32 ms |
8272 KB |
Execution killed with signal 11 |
69 |
Halted |
0 ms |
0 KB |
- |