#include<bits/stdc++.h>
using namespace std;
#define f first
#define s second
#define pb push_back
typedef long long ll;
ll i, j, k, t, l, x, y, w, ans;
vector<ll> v[100005];
map<pair<ll, ll>, ll> m, p, dp;
set<ll> s;
set<ll> :: iterator it, it1;
ll max_weights(int N, int M, std::vector<int> X, std::vector<int> Y, std::vector<int> W)
{
for(i = 0; i < M; i++)
{
X[i]++; Y[i]++;
v[X[i] + 1].pb(Y[i]);
m[{X[i], Y[i]}] = W[i];
}
for(i = 1; i <= N + 1; i++)
{
v[i].pb(0), v[i].pb(N + 1);
sort(v[i].begin(), v[i].end());
/*for(auto j : v[i])
cout << j << ' ';
cout << endl; */
}
for(i = 1; i <= N; i++)
{
for(j = 0; j < v[i - 1].size(); j++)
if(v[i - 1][j]) s.insert(v[i - 1][j] - 1);
for(j = 0; j < v[i].size() - 1; j++)
s.insert(v[i][j]);
for(j = 0; j < v[i + 1].size() - 1; j++)
s.insert(v[i + 1][j]);
s.insert(N);
for(it = s.begin(); it != s.end(); it++)
{
p[{i, *it}] = 0;
if(m[{i,*it}]) p[{i, *it}] = m[{i, *it}];
if(it != s.begin())
{
it1 = it;
it1--;
p[{i, *it}] += p[{i, *it1}];
}
// cout << *it << ' ' << p[{i, *it}] << ' ';
}
//cout << endl;
s.clear();
}
for(i = 2; i <= N; i++)
{
k = 0; t = 0;
for(j = 0; j < v[i].size() - 1; j++)
{
if(j && v[i][j] == v[i][j - 1]) continue;
if(!j)
{
//cout << p[{i, v[i - 1][l + 1] - 1}] << endl;
for(l = 0; l < v[i - 1].size() - 1; l++)
dp[{i, j}] = max(dp[{i, j}], dp[{i - 1, l}] + p[{i, v[i - 1][l + 1] - 1}]);
}
else
{
while(k < v[i - 1].size() && v[i - 1][k] < v[i][j])
{
if(!v[i - 1][k])
{
if(i == 2) { dp[{i, j}] = max(dp[{i, j}], p[{1, v[i][j]}]); k++; continue; }
while(t < v[i - 2].size() && v[i - 2][t] < v[i][j])
{
dp[{i, j}] = max(dp[{i, j}], dp[{i - 2, t}] + p[{i - 1, v[i][j]}]);
t++;
}
}
else
dp[{i, j}] = max(dp[{i, j}], dp[{i - 1, k}] + p[{i - 1, v[i][j]}] - p[{i - 1, v[i - 1][k]}]);
k++;
}
if(j - 1) dp[{i, j}] = max(dp[{i, j}], dp[{i, j - 1}] + p[{i - 1, v[i][j]}] - p[{i - 1, v[i][j - 1]}]);
//cout << p[{i - 1, v[i][j]}] << endl;
}
//cout << i << ' ' << v[i][j] << ' ' << dp[{i, j}] << endl;
}
}
for(i = 0; i < v[N].size() - 1; i++)
ans = max(ans, dp[{N, i}]);
return ans;
}
Compilation message
fish.cpp: In function 'll max_weights(int, int, std::vector<int>, std::vector<int>, std::vector<int>)':
fish.cpp:33:22: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
33 | for(j = 0; j < v[i - 1].size(); j++)
| ~~^~~~~~~~~~~~~~~~~
fish.cpp:35:22: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
35 | for(j = 0; j < v[i].size() - 1; j++)
| ~~^~~~~~~~~~~~~~~~~
fish.cpp:37:22: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
37 | for(j = 0; j < v[i + 1].size() - 1; j++)
| ~~^~~~~~~~~~~~~~~~~~~~~
fish.cpp:58:22: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
58 | for(j = 0; j < v[i].size() - 1; j++)
| ~~^~~~~~~~~~~~~~~~~
fish.cpp:64:30: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
64 | for(l = 0; l < v[i - 1].size() - 1; l++)
| ~~^~~~~~~~~~~~~~~~~~~~~
fish.cpp:69:25: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
69 | while(k < v[i - 1].size() && v[i - 1][k] < v[i][j])
| ~~^~~~~~~~~~~~~~~~~
fish.cpp:74:33: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
74 | while(t < v[i - 2].size() && v[i - 2][t] < v[i][j])
| ~~^~~~~~~~~~~~~~~~~
fish.cpp:90:18: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
90 | for(i = 0; i < v[N].size() - 1; i++)
| ~~^~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
655 ms |
72892 KB |
Output is correct |
2 |
Correct |
786 ms |
85532 KB |
Output is correct |
3 |
Correct |
194 ms |
37068 KB |
Output is correct |
4 |
Correct |
212 ms |
37080 KB |
Output is correct |
5 |
Execution timed out |
1076 ms |
116944 KB |
Time limit exceeded |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2644 KB |
Output is correct |
2 |
Execution timed out |
1014 ms |
93984 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
196 ms |
36980 KB |
Output is correct |
2 |
Correct |
203 ms |
37160 KB |
Output is correct |
3 |
Incorrect |
350 ms |
47640 KB |
1st lines differ - on the 1st token, expected: '21261825233649', found: '21056276734778' |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2644 KB |
Output is correct |
2 |
Correct |
2 ms |
2644 KB |
Output is correct |
3 |
Correct |
2 ms |
2552 KB |
Output is correct |
4 |
Correct |
2 ms |
2644 KB |
Output is correct |
5 |
Correct |
2 ms |
2644 KB |
Output is correct |
6 |
Correct |
2 ms |
2644 KB |
Output is correct |
7 |
Correct |
2 ms |
2648 KB |
Output is correct |
8 |
Correct |
2 ms |
2644 KB |
Output is correct |
9 |
Incorrect |
3 ms |
2772 KB |
1st lines differ - on the 1st token, expected: '216624184325', found: '214211534000' |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2644 KB |
Output is correct |
2 |
Correct |
2 ms |
2644 KB |
Output is correct |
3 |
Correct |
2 ms |
2552 KB |
Output is correct |
4 |
Correct |
2 ms |
2644 KB |
Output is correct |
5 |
Correct |
2 ms |
2644 KB |
Output is correct |
6 |
Correct |
2 ms |
2644 KB |
Output is correct |
7 |
Correct |
2 ms |
2648 KB |
Output is correct |
8 |
Correct |
2 ms |
2644 KB |
Output is correct |
9 |
Incorrect |
3 ms |
2772 KB |
1st lines differ - on the 1st token, expected: '216624184325', found: '214211534000' |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2644 KB |
Output is correct |
2 |
Correct |
2 ms |
2644 KB |
Output is correct |
3 |
Correct |
2 ms |
2552 KB |
Output is correct |
4 |
Correct |
2 ms |
2644 KB |
Output is correct |
5 |
Correct |
2 ms |
2644 KB |
Output is correct |
6 |
Correct |
2 ms |
2644 KB |
Output is correct |
7 |
Correct |
2 ms |
2648 KB |
Output is correct |
8 |
Correct |
2 ms |
2644 KB |
Output is correct |
9 |
Incorrect |
3 ms |
2772 KB |
1st lines differ - on the 1st token, expected: '216624184325', found: '214211534000' |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
196 ms |
36980 KB |
Output is correct |
2 |
Correct |
203 ms |
37160 KB |
Output is correct |
3 |
Incorrect |
350 ms |
47640 KB |
1st lines differ - on the 1st token, expected: '21261825233649', found: '21056276734778' |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
655 ms |
72892 KB |
Output is correct |
2 |
Correct |
786 ms |
85532 KB |
Output is correct |
3 |
Correct |
194 ms |
37068 KB |
Output is correct |
4 |
Correct |
212 ms |
37080 KB |
Output is correct |
5 |
Execution timed out |
1076 ms |
116944 KB |
Time limit exceeded |
6 |
Halted |
0 ms |
0 KB |
- |