#include "fish.h"
#include <bits/stdc++.h>
using namespace std;
long long max_weights(int N, int M, std::vector<int> X, std::vector<int> Y,
std::vector<int> W) {
vector<vector<pair<int,int>>> poses(N);
for (int i = 0; i < M; ++i)
{
poses[X[i]].push_back({Y[i],W[i]});
}
for (int i = 0; i < N; ++i)
{
if (poses[i].size()==0) poses[i].push_back({0,0});
sort(poses[i].begin(), poses[i].end());
poses[i].push_back({N,0});
}
vector<vector<vector<int>>> dp(N);
for (int i = 0; i < N; ++i)
{
dp[i].resize(poses[i].size(),vector<int>(3,-1));
}
function<int(int,int,int)> query = [&](int node, int l, int r)->int{
int ans = 0;
for (int i = 0; i < poses[node].size(); i++){
if (poses[node][i].first>=l && poses[node][i].first<=r){
ans+=poses[node][i].second;
}
}
return ans;
};
function<int(int,int,int)> f = [&](int pos, int node, int flag)->int{
if (pos==N) return 0;
if (dp[pos][node][flag]!=-1) return dp[pos][node][flag];
dp[pos][node][flag]=0;
if (flag<=1){
//0 artiyo
//1 artiyo, arkadan ekleme
if (node+1<dp[pos].size()){
//bi yukari git
int cur = f(pos,node+1,flag);
if (flag==0 && pos-1>=0){
cur+=query(pos-1,poses[pos][node].first,poses[pos][node+1].first-1);
}
dp[pos][node][flag]=max(dp[pos][node][flag],cur);
}
}
else {
assert(node>0 && poses[pos][node].first>0);
cout<<pos<<" "<<node<<endl;
if (poses[pos][node-1].first>0){
dp[pos][node][flag]=max(dp[pos][node][flag],f(pos,node-1,flag)+poses[pos][node-1].second);
}
}
if (pos+1<N){
int buyu = lower_bound(poses[pos+1].begin(),poses[pos+1].end(),pair<int,int>{poses[pos][node].first,0})-poses[pos+1].begin();
if (flag<=1 && buyu<poses[pos+1].size()){
dp[pos][node][flag]=max(dp[pos][node][flag],f(pos+1,buyu,0)+query(pos,poses[pos][node].first,poses[pos+1][buyu].first-1));
}
if (buyu==poses[pos+1].size() || poses[pos+1][buyu].first!=poses[pos][node].first) buyu--;
if (buyu>0){
dp[pos][node][flag]=max(dp[pos][node][flag],f(pos+1,buyu,flag&2))+query(pos+1,poses[pos+1][buyu].first,poses[pos][node].first-1);
}
}
if (pos+2<N){
dp[pos][node][flag]=max(dp[pos][node][flag],f(pos+2,0,0));
dp[pos][node][flag]=max(dp[pos][node][flag],f(pos+2,0,1)+query(pos+1,0,poses[pos][node].first-1));
}
return dp[pos][node][flag];
};
return f(0,0,0);
}
Compilation message
fish.cpp: In lambda function:
fish.cpp:25:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
25 | for (int i = 0; i < poses[node].size(); i++){
| ~~^~~~~~~~~~~~~~~~~~~~
fish.cpp: In lambda function:
fish.cpp:39:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
39 | if (node+1<dp[pos].size()){
| ~~~~~~^~~~~~~~~~~~~~~
fish.cpp:57:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
57 | if (flag<=1 && buyu<poses[pos+1].size()){
| ~~~~^~~~~~~~~~~~~~~~~~~~
fish.cpp:60:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
60 | if (buyu==poses[pos+1].size() || poses[pos+1][buyu].first!=poses[pos][node].first) buyu--;
| ~~~~^~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1071 ms |
68296 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Execution timed out |
1094 ms |
75412 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
45 ms |
45708 KB |
Output is correct |
2 |
Incorrect |
45 ms |
45648 KB |
1st lines differ - on the 1st token, expected: '882019', found: '0' |
3 |
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 |
0 ms |
348 KB |
1st lines differ - on the 1st token, expected: '4044', found: '2022' |
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 |
0 ms |
348 KB |
1st lines differ - on the 1st token, expected: '4044', found: '2022' |
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 |
0 ms |
348 KB |
1st lines differ - on the 1st token, expected: '4044', found: '2022' |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
45 ms |
45708 KB |
Output is correct |
2 |
Incorrect |
45 ms |
45648 KB |
1st lines differ - on the 1st token, expected: '882019', found: '0' |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1071 ms |
68296 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |