#include "fish.h"
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int INF=1e9;
const ll LINF=1e18;
#define fi first
#define se second
#define pii pair<int,int>
#define mid ((l+r)/2)
#define sz(a) (int((a).size()))
#define all(a) a.begin(),a.end()
#define endl "\n"
#define PRINT(x) cerr<<#x<<'='<<x<<endl;
#define pb push_back
#define PRINTvec(niz) { cerr<<#niz<<"="; for(auto _i:niz) cerr<<_i<<" "; cerr<<endl; }
long long max_weights(int N,int M,vector<int> X,vector<int> Y,vector<int> W){
assert(N<=3000);
vector<vector<int>> we(N,vector<int>(N,0));
for(int i=0;i<M;i++){
we[X[i]][Y[i]]=W[i];
}
vector<vector<vector<ll>>> dp(N,vector<vector<ll>>(N+1,vector<ll>(3,0)));
for(int i=1;i<N;i++){
ll pref_max=0;
for(int tsz=N-1;tsz>=0;tsz--){
pref_max=max(pref_max+we[i][tsz],max({dp[i-1][tsz+1][0],dp[i-1][tsz+1][1],dp[i-1][tsz+1][2]})+we[i][tsz]);
dp[i][tsz][0]=pref_max;
}
for(int tsz=N;tsz>=0;tsz--){
dp[i][tsz][2]=max({dp[i-1][tsz][0],dp[i-1][tsz][1],dp[i-1][tsz][2]});
}
vector<ll> pref(N,0); pref[0]=we[i-1][0];
for(int j=1;j<N;j++){
pref[j]=pref[j-1]+we[i-1][j];
}
if(i>1){
pref_max=0;
for(int tsz=1;tsz<=N;tsz++){
pref_max=max(pref_max,max({dp[i-2][tsz][0],dp[i-2][tsz][1],dp[i-2][tsz][2]}));
dp[i][tsz][1]=pref_max+pref[tsz-1];
}
pref_max=0;
for(int tsz=N;tsz>=1;tsz--){
pref_max=max(pref_max,max({dp[i-2][tsz][0],dp[i-2][tsz][1],dp[i-2][tsz][2]})+pref[tsz-1]);
dp[i][tsz][1]=max(dp[i][tsz][1],pref_max);
}
}
else{
for(int tsz=1;tsz<=N;tsz++){
dp[i][tsz][1]=pref[tsz-1];
}
}
pref_max=0;
for(int tsz=2;tsz<=N;tsz++){
pref_max=max(pref_max+we[i-1][tsz-1],max(dp[i-1][tsz-1][1],dp[i-1][tsz-1][2])+we[i-1][tsz-1]);
dp[i][tsz][1]=max(dp[i][tsz][1],pref_max);
}
}
/*
for(int i=0;i<N;i++){
PRINT(i);
for(int p=0;p<3;p++){
for(int tsz=0;tsz<=N;tsz++){
cerr<<"dp["<<i<<"]["<<tsz<<"]["<<p<<"]="<<dp[i][tsz][p]<<endl;
}
cerr<<endl;
}
cerr<<"XXXXXXXXXXXXXXXXXXXXX"<<endl<<endl;
}
*/
ll res=0;
for(int tsz=0;tsz<=N;tsz++){
res=max({res,dp[N-1][tsz][0],dp[N-1][tsz][1],dp[N-1][tsz][2]});
}
return res;
}
/*
4 3
2 2 1
0 0 1
1 1 1
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
24 ms |
5584 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Runtime error |
48 ms |
10896 KB |
Execution killed with signal 6 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
340 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
304 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
296 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 |
300 KB |
Output is correct |
9 |
Incorrect |
2 ms |
1620 KB |
1st lines differ - on the 1st token, expected: '216624184325', found: '199904465818' |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
304 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
296 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 |
300 KB |
Output is correct |
9 |
Incorrect |
2 ms |
1620 KB |
1st lines differ - on the 1st token, expected: '216624184325', found: '199904465818' |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
304 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
296 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 |
300 KB |
Output is correct |
9 |
Incorrect |
2 ms |
1620 KB |
1st lines differ - on the 1st token, expected: '216624184325', found: '199904465818' |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
340 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
24 ms |
5584 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |