#include "fish.h"
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
ll max_weights(int n, int m, vector<int> x, vector<int> y, vector<int> w){
int h=0;
for(int i=0;i<m;i++) h=max(h,y[i]);
h+=2;
ll fish[n][h]; memset(fish,0,sizeof fish);
for(int i=0;i<m;i++) fish[x[i]][y[i]+1]=w[i];
for(int i=0;i<n;i++)
for(int j=1;j<h;j++)
fish[i][j]+=fish[i][j-1];
ll dp[n][2][h][h]; memset(dp,0,sizeof dp);
for(int i=1;i<n;i++){
for(int j=0;j<h;j++){
// decreasing:
ll prev=0;
int pos=0;
for(int k=h-1;k>=j;k--){
ll aux=max(dp[i-1][0][k][j],dp[i-1][1][k][j]);
// hmmmm
if(aux>=prev){
pos=k;
prev=aux;
}
}
if(j){
for(int k=0;k<=j;k++){
dp[i][0][j][k]+=prev;
dp[i][0][j][k]+=fish[i][j]-fish[i][k];
}
}
else{
for(int k=0;k<h;k++){
dp[i][0][j][k]+=prev;
if(k>pos) dp[i][0][j][k]+=fish[i-1][k]-fish[i-1][pos];
}
}
// increasing:
prev=0;
for(int k=0;k<=j;k++)
prev=max(prev,dp[i-1][1][k][j]);
for(int k=0;k<h;k++){
dp[i][1][j][k]+=prev;
if(j>=k) dp[i][1][j][k]+=fish[i][j]-fish[i][k];
else dp[i][1][j][k]+=fish[i-1][k]-fish[i-1][j];
}
}
}
/*
for(int i=0;i<n;i++){
for(int j=0;j<h;j++){
for(int k=0;k<h;k++){
printf("%d:\n",i);
printf("decreasing:\n");
printf("%d %d -> %lld\n",j,k,dp[i][0][j][k]);
printf("increasing:\n");
printf("%d %d -> %lld\n",j,k,dp[i][1][j][k]);
printf("\n");
}
}
}
*/
ll res=0;
for(int i=0;i<h;i++)
for(int j=0;j<h;j++)
res=max({res,dp[n-1][0][i][j],dp[n-1][1][i][j]});
return res;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
968 ms |
2097156 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Runtime error |
777 ms |
2097152 KB |
Execution killed with signal 9 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
8020 KB |
Output is correct |
2 |
Correct |
8 ms |
8020 KB |
Output is correct |
3 |
Incorrect |
21 ms |
9496 KB |
1st lines differ - on the 1st token, expected: '21261825233649', found: '1999989354' |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 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 |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 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 |
Incorrect |
1 ms |
340 KB |
1st lines differ - on the 1st token, expected: '216624184325', found: '9393607892' |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 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 |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 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 |
Incorrect |
1 ms |
340 KB |
1st lines differ - on the 1st token, expected: '216624184325', found: '9393607892' |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 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 |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 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 |
Incorrect |
1 ms |
340 KB |
1st lines differ - on the 1st token, expected: '216624184325', found: '9393607892' |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
8020 KB |
Output is correct |
2 |
Correct |
8 ms |
8020 KB |
Output is correct |
3 |
Incorrect |
21 ms |
9496 KB |
1st lines differ - on the 1st token, expected: '21261825233649', found: '1999989354' |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
968 ms |
2097156 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |