#include "fish.h"
#include<bits/stdc++.h>
using namespace std;
const int maxn=100000+10,maxh=3000+10;
int n,m;
vector<pair<int,int>>allc[maxn];
long long dp[maxh][maxh],inf=1e16,all[maxh][maxh],dpp[maxh][maxh];
long long solve(){
for(int i=0;i<=n;i++){
dp[0][i]=-inf;
}
dp[0][0]=0;
long long mainres=0;
for(int i=1;i<=n;i++){
for(int j=0;j<=n;j++){
dp[i][j]=dpp[i][j]=-inf;
}
long long unnow=-inf;
for(int j=n;j>=0;j--){
dp[i][j]=max(dp[i][j],unnow);
dp[i][j]=max(dp[i-1][j],dp[i][j]);
dpp[i][j]=max(dpp[i][j],dp[i-1][j]);
unnow=max(unnow,dp[i-1][j])+all[i][j];
}
unnow=-inf;
if(i==1){
unnow=0;
}
for(int j=1;j<=n;j++){
unnow=max(unnow+all[i-1][j],dpp[i-1][j]);
dp[i][j]=max(dp[i][j],unnow);
if(i==n){
mainres=max(mainres,dp[i][j]);
}
dpp[i][j]=max(dpp[i][j],unnow);
}
}
/* for(int i=0;i<=n;i++){
for(int j=0;j<=n;j++){
cout<<dp[i][j]<<" ";
}
cout<<"\n";
}*/
return mainres;
}
long long max_weights(int N, int M, std::vector<int> X, std::vector<int> Y,
std::vector<int> W) {
n=N;
m=M;
for(int i=0;i<m;i++){
Y[i]++;
X[i]++;
all[X[i]][Y[i]]+=W[i];
allc[X[i]].push_back(make_pair(Y[i],W[i]));
}
for(int i=0;i<=n;i++){
allc[i].push_back(make_pair(1,0));
allc[i].push_back(make_pair(n,0));
sort(allc[i].begin(),allc[i].end());
}
return solve();
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1063 ms |
309700 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
8028 KB |
1st lines differ - on the 1st token, expected: '2', found: '1' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1069 ms |
215180 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
8028 KB |
1st lines differ - on the 1st token, expected: '3', found: '2' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
8028 KB |
1st lines differ - on the 1st token, expected: '3', found: '2' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
8028 KB |
1st lines differ - on the 1st token, expected: '3', found: '2' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1069 ms |
215180 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1063 ms |
309700 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |