#include "fish.h"
#include <bits/stdc++.h>
using namespace std;
long long max_weights(int n,int m,vector <int> x,vector <int> y,vector <int> w){
bool sub1=1;
for (int i:x){
if (i%2==1) sub1=0;
}
if (sub1){
return accumulate(w.begin(),w.end(),0ll);
}
if (*max_element(x.begin(),x.end())<=1){
long long mx[2]={0,0};
for (int i=0; i<m; i++) mx[x[i]]+=w[i];
if (n==2) return max(mx[0],mx[1]);
int a[2][n];
for (int i=0; i<2; i++){
for (int j=0; j<n; j++) a[i][j]=0;
}
for (int i=0; i<m; i++) a[x[i]][y[i]]=w[i];
long long ans=mx[1],cur=mx[1];
for (int j=0; j<n; j++){
cur+=a[0][j];
cur-=a[1][j];
ans=max(ans,cur);
}
return ans;
}
if (n<=300&&*max_element(y.begin(),y.end())<=8||*max_element(y.begin(),y.end())==0){
int l=*max_element(y.begin(),y.end())+1;
long long a[l+1][n+1],s[n+1][l+1];
for (int i=0; i<=n; i++){
for (int j=0; j<=l; j++) a[j][i]=s[i][j]=0;
}
for (int i=0; i<m; i++) a[y[i]+1][x[i]+1]=w[i];
for (int col=0; col<=n; col++){
for (int i=1; i<=l; i++) s[col][i]=s[col][i-1]+a[i][col];
}
long long dp[n+1][l+1][l+1];
for (int i=0; i<=n; i++){
for (int j=0; j<=l; j++){
for (int k=0; k<=l; k++) dp[i][j][k]=-1e18;
}
}
dp[0][0][0]=0;
for (int i=0; i<n; i++){
for (int j=0; j<=l; j++){
for (int k=0; k<=l; k++){
for (int nxt=0; nxt<=l; nxt++){
dp[i+1][k][nxt]=max(dp[i+1][k][nxt],dp[i][j][k]+(nxt>max(j,k)?s[i][nxt]-s[i][max(j,k)]:0ll)-s[i+1][min(k,nxt)]+(i+2<=n?s[i+2][nxt]:0ll));
}
}
}
}
long long ans=0;
for (int i=0; i<=n; i++){
for (int j=0; j<=l; j++){
for (int k=0; k<=l; k++){
ans=max(ans,dp[i][j][k]);
}
}
}
return ans;
}
}
Compilation message
fish.cpp: In function 'long long int max_weights(int, int, std::vector<int>, std::vector<int>, std::vector<int>)':
fish.cpp:31:12: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
31 | if (n<=300&&*max_element(y.begin(),y.end())<=8||*max_element(y.begin(),y.end())==0){
| ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
fish.cpp:67:1: warning: control reaches end of non-void function [-Wreturn-type]
67 | }
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
26 ms |
3536 KB |
Output is correct |
2 |
Correct |
27 ms |
4280 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
112 ms |
12216 KB |
Output is correct |
6 |
Correct |
89 ms |
12148 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
48 ms |
7500 KB |
Output is correct |
3 |
Correct |
60 ms |
9152 KB |
Output is correct |
4 |
Correct |
32 ms |
3532 KB |
Output is correct |
5 |
Correct |
35 ms |
4356 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
296 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
296 KB |
Output is correct |
12 |
Correct |
31 ms |
4044 KB |
Output is correct |
13 |
Correct |
36 ms |
4452 KB |
Output is correct |
14 |
Correct |
32 ms |
4004 KB |
Output is correct |
15 |
Correct |
27 ms |
4264 KB |
Output is correct |
16 |
Correct |
25 ms |
3972 KB |
Output is correct |
17 |
Correct |
29 ms |
4328 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
8 ms |
6484 KB |
Output is correct |
3 |
Correct |
22 ms |
7972 KB |
Output is correct |
4 |
Correct |
18 ms |
7556 KB |
Output is correct |
5 |
Correct |
33 ms |
9036 KB |
Output is correct |
6 |
Correct |
30 ms |
9176 KB |
Output is correct |
7 |
Correct |
34 ms |
9308 KB |
Output is correct |
8 |
Correct |
34 ms |
9292 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 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 |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
2 ms |
616 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
2 ms |
468 KB |
Output is correct |
13 |
Correct |
1 ms |
300 KB |
Output is correct |
14 |
Correct |
1 ms |
468 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 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 |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
2 ms |
616 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
2 ms |
468 KB |
Output is correct |
13 |
Correct |
1 ms |
300 KB |
Output is correct |
14 |
Correct |
1 ms |
468 KB |
Output is correct |
15 |
Execution timed out |
1086 ms |
213668 KB |
Time limit exceeded |
16 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 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 |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
2 ms |
616 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
2 ms |
468 KB |
Output is correct |
13 |
Correct |
1 ms |
300 KB |
Output is correct |
14 |
Correct |
1 ms |
468 KB |
Output is correct |
15 |
Execution timed out |
1086 ms |
213668 KB |
Time limit exceeded |
16 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
8 ms |
6484 KB |
Output is correct |
3 |
Correct |
22 ms |
7972 KB |
Output is correct |
4 |
Correct |
18 ms |
7556 KB |
Output is correct |
5 |
Correct |
33 ms |
9036 KB |
Output is correct |
6 |
Correct |
30 ms |
9176 KB |
Output is correct |
7 |
Correct |
34 ms |
9308 KB |
Output is correct |
8 |
Correct |
34 ms |
9292 KB |
Output is correct |
9 |
Runtime error |
902 ms |
2097152 KB |
Execution killed with signal 9 |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
26 ms |
3536 KB |
Output is correct |
2 |
Correct |
27 ms |
4280 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
112 ms |
12216 KB |
Output is correct |
6 |
Correct |
89 ms |
12148 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
48 ms |
7500 KB |
Output is correct |
9 |
Correct |
60 ms |
9152 KB |
Output is correct |
10 |
Correct |
32 ms |
3532 KB |
Output is correct |
11 |
Correct |
35 ms |
4356 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
296 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
296 KB |
Output is correct |
18 |
Correct |
31 ms |
4044 KB |
Output is correct |
19 |
Correct |
36 ms |
4452 KB |
Output is correct |
20 |
Correct |
32 ms |
4004 KB |
Output is correct |
21 |
Correct |
27 ms |
4264 KB |
Output is correct |
22 |
Correct |
25 ms |
3972 KB |
Output is correct |
23 |
Correct |
29 ms |
4328 KB |
Output is correct |
24 |
Correct |
0 ms |
212 KB |
Output is correct |
25 |
Correct |
8 ms |
6484 KB |
Output is correct |
26 |
Correct |
22 ms |
7972 KB |
Output is correct |
27 |
Correct |
18 ms |
7556 KB |
Output is correct |
28 |
Correct |
33 ms |
9036 KB |
Output is correct |
29 |
Correct |
30 ms |
9176 KB |
Output is correct |
30 |
Correct |
34 ms |
9308 KB |
Output is correct |
31 |
Correct |
34 ms |
9292 KB |
Output is correct |
32 |
Correct |
0 ms |
212 KB |
Output is correct |
33 |
Correct |
0 ms |
212 KB |
Output is correct |
34 |
Correct |
0 ms |
212 KB |
Output is correct |
35 |
Correct |
1 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 |
1 ms |
212 KB |
Output is correct |
40 |
Correct |
1 ms |
340 KB |
Output is correct |
41 |
Correct |
2 ms |
616 KB |
Output is correct |
42 |
Correct |
1 ms |
340 KB |
Output is correct |
43 |
Correct |
2 ms |
468 KB |
Output is correct |
44 |
Correct |
1 ms |
300 KB |
Output is correct |
45 |
Correct |
1 ms |
468 KB |
Output is correct |
46 |
Execution timed out |
1086 ms |
213668 KB |
Time limit exceeded |
47 |
Halted |
0 ms |
0 KB |
- |