#include "fish.h"
#include <vector>
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define fs first
#define sc second
const ll inf = 1e18;
const int mxn = 330;
ll dp[mxn][mxn];
ll pref[mxn];
vector<pii> fish[mxn];
ll f(int idx,int s,int e){
ll re = 0;
for(auto &[pos,w]:fish[idx]){
if(pos>s&&pos<=e)re += w;
}
return re;
}
long long max_weights(int N, int M, std::vector<int> X, std::vector<int> Y,
std::vector<int> W) {
for(int i = 0;i<M;i++){
fish[X[i]].push_back(pii(Y[i],W[i]));
}
for(int i = 0;i<N;i++)sort(fish[i].begin(),fish[i].end());
for(int i = 0;i<N;i++){
dp[0][i] = f(1,0,i);
pref[i] = dp[0][i];
}
ll big = 0;
for(int i = 1;i<N;i++){
ll tmp[mxn] = {};
for(auto &[pos,w]:fish[i-1])tmp[pos] += w;
ll own[mxn] = {};
for(auto &[pos,w]:fish[i])own[pos] += w;
for(int j = 1;j<N;j++)tmp[j] += tmp[j-1],own[j] += own[j-1];
ll mx1 = -inf,mx2 = -inf;//dp[i-1],dp[i-2],others
for(int j = 0;j<N;j++){
mx1 = max(mx1,dp[i-1][j]-tmp[j]-own[j]);
if(i>=2)mx2 = max(mx2,dp[i-2][j]-tmp[j]);
dp[i][j] = max(dp[i][j],mx1+tmp[j]+f(i+1,-1,j));
dp[i][j] = max(dp[i][j],mx2+tmp[j]+f(i+1,-1,j));
dp[i][j] = max(dp[i][j],big+f(i-1,-1,j)+f(i+1,-1,j));
}
for(int j = 0;j<N;j++)pref[j] = max(pref[j],dp[i][j]);
if(i-2>=0){
for(int j = 0;j<N;j++){
big = max(big,dp[i-2][j]);
}
}
}
ll ans = 0;
/*
for(int i = 0;i<N;i++){
for(int j = 0;j<N;j++)cerr<<dp[i][j]<<' ';cerr<<endl;
}cerr<<endl;
*/
for(int i = 0;i<N;i++){
for(int j = 0;j<N;j++)ans = max(ans,dp[i][j]);
}
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
22 ms |
5828 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Runtime error |
46 ms |
10960 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
348 KB |
Execution killed with signal 11 |
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 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Incorrect |
0 ms |
348 KB |
1st lines differ - on the 1st token, expected: '8866', found: '7755' |
6 |
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 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Incorrect |
0 ms |
348 KB |
1st lines differ - on the 1st token, expected: '8866', found: '7755' |
6 |
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 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Incorrect |
0 ms |
348 KB |
1st lines differ - on the 1st token, expected: '8866', found: '7755' |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
348 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
22 ms |
5828 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |