///~~~LOTA~~~///
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define append push_back
#define add insert
#define nl '\n'
#define ff first
#define ss second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define all(x) (x).begin(),(x).end()
#define L0TA ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define terminator main
int n,m;
vector<int> x,y,w;
ll dps(){
ll hs[n+1][n+1];
ll dp[n+1][n+1];
ll dp2[n+1][n+1];
for(int i=0;i<=n;i++)
for(int j=0;j<=n;j++)
hs[i][j]=dp[i][j]=dp2[i][j]=0;
for(int i=1;i<=n;i++)
dp[0][i]=dp2[0][i]=-1e17;
for(int i=0;i<m;i++)
hs[x[i]+1][y[i]+1]+=w[i];
for(int i=1;i<=n;i++)
for(int j=0;j<n;j++)
hs[i][j+1]+=hs[i][j];
for(int i=1;i<=n;i++){
for(int j=0;j<=n;j++){
for(int k=0;k<=n;k++){
if(j<k){
dp[i][j]=max(dp[i][j],dp[i-1][k]+hs[i][k]-hs[i][j]);
dp2[i][k]=max(dp2[i][k],dp[i-1][k]+hs[i][k]-hs[i][j]);
}
else{
dp[i][j]=max(dp[i][j],dp2[i-1][k]+hs[i-1][j]-hs[i-1][k]);
dp2[i][j]=max(dp2[i][j],dp2[i-1][k]+hs[i-1][j]-hs[i-1][k]);
}
}
dp2[i][j]=max(dp2[i][j],dp[i-1][j]+hs[i][j]);
}
}
ll ans=0;
for(int i=0;i<=n;i++)
ans=max(ans,max(dp[n][i],dp2[n][i]));
return ans;
}
ll xs(){
ll hs[3][n+1];
for(int i=0;i<m;i++)
hs[x[i]+1][y[i]+1]+=w[i];
for(int i=1;i<3;i++)
for(int j=0;j<n;j++)
hs[i][j+1]+=hs[i][j];
ll ans=0;
for(int i=0;i<=n;i++)
ans=max(ans,hs[1][i]+hs[2][n]-hs[2][i]);
return ans;
}
ll ys(){
ll hs[n+1][2];
ll dp[n+1][2];
ll dp2[n+1][2];
for(int i=0;i<=n;i++)
for(int j=0;j<2;j++)
hs[i][j]=dp[i][j]=dp2[i][j]=0;
for(int i=1;i<=n;i++)
dp[0][i]=dp2[0][i]=-1e17;
for(int i=0;i<m;i++)
hs[x[i]+1][y[i]+1]+=w[i];
for(int i=1;i<=n;i++)
for(int j=0;j<n;j++)
hs[i][j+1]+=hs[i][j];
for(int i=1;i<2;i++)
dp[0][i]=dp2[0][i]=-1e17;
for(int i=1;i<=n;i++){
for(int j=0;j<2;j++){
for(int k=0;k<2;k++){
if(j<k){
dp[i][j]=max(dp[i][j],dp[i-1][k]+hs[i][k]-hs[i][j]);
dp2[i][k]=max(dp2[i][k],dp[i-1][k]+hs[i][k]-hs[i][j]);
}
else{
dp[i][j]=max(dp[i][j],dp2[i-1][k]+hs[i-1][j]-hs[i-1][k]);
dp2[i][j]=max(dp2[i][j],dp2[i-1][k]+hs[i-1][j]-hs[i-1][k]);
}
}
dp2[i][j]=max(dp2[i][j],dp[i-1][j]+hs[i][j]);
}
}
ll ans=0;
for(int i=0;i<2;i++)
ans=max(ans,max(dp[n][i],dp2[n][i]));
return ans;
}
ll max_weights(int N,int M,vector<int> X,vector<int> Y,vector<int> W){
n=N;
m=M;
x=X;
y=Y;
w=W;
if(n<N) return dps();
int mx,my;
ll o=0;
for(int i=mx=my=0;i<m;i++){
mx=max(mx,x[i]);
my=max(my,y[i]);
o+=w[i];
}
if(mx<2) return xs();
if(my<1) return ys();
return o;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
16 ms |
6748 KB |
1st lines differ - on the 1st token, expected: '40313272768926', found: '3836249277971329924' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
348 KB |
1st lines differ - on the 1st token, expected: '2', found: '281463510196815' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
2648 KB |
1st lines differ - on the 1st token, expected: '10082010', found: '4187135213373620462' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Incorrect |
1 ms |
348 KB |
1st lines differ - on the 1st token, expected: '4044', found: '281451953669008' |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Incorrect |
1 ms |
348 KB |
1st lines differ - on the 1st token, expected: '4044', found: '281451953669008' |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Incorrect |
1 ms |
348 KB |
1st lines differ - on the 1st token, expected: '4044', found: '281451953669008' |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
2648 KB |
1st lines differ - on the 1st token, expected: '10082010', found: '4187135213373620462' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
16 ms |
6748 KB |
1st lines differ - on the 1st token, expected: '40313272768926', found: '3836249277971329924' |
2 |
Halted |
0 ms |
0 KB |
- |