#include <bits/stdc++.h>
using namespace std;
vector<vector<int>> V;
struct info{
int y;
int w;
int flag;
};
struct CustomCompare
{
bool operator()(info const& p, info const& p1)
{
return (p.y > p1.y) || (p.y == p1.y && p.flag > p1.flag);
}
};
long long max_weights(int N, int M, std::vector<int> X, std::vector<int> Y, std::vector<int> W){
// se X[i] è pari, allora posso ergere ponti per prendere tutti
bool subtask1 = true;
bool subtask2 = true;
bool subtask3 = true;
bool subtask4 = true;
long long ans = 0;
// for(int i = 0; i < (int)X.size(); i++)
// V[X[i]][Y[i]] = W[i];
for(int i = 0; i < (int)X.size(); i++){
subtask1 &= X[i] % 2 == 0;
subtask2 &= X[i] <= 1;
subtask3 &= Y[i] == 0;
subtask4 &= N <= 300;
}
if(subtask1){
ans = accumulate(W.begin(), W.end(), 0L);
return ans;
}
if(subtask2){
if(N == 1) return 0;
if(N == 2){
long long x0 = 0, x1 = 0;
for(int i = 0; i < (int)X.size(); i++){
if(X[i] == 1) x1 += W[i];
else x0 += W[i];
}
return max(x1, x0);
}
priority_queue<info, vector<info>, CustomCompare> pq;
long long x1 = 0;
for(int i = 0; i < (int)X.size(); i++){
pq.push({Y[i], W[i], X[i] == 0});
if(X[i] == 1) x1 += W[i];
}
long long curr = x1;
ans = curr;
while(!pq.empty()){
info p = pq.top();
pq.pop();
if(p.flag) curr += p.w, ans = max(ans, curr);
else curr -= p.w;
}
return ans;
}
if(subtask3){
// dp particolare
vector<array<int, 3>> A;
long long dp[M][2];
long long memo[M];
for(int i = 0; i < M; i++) A.push_back({X[i], Y[i], W[i]});
sort(A.begin(), A.end());
if(M == 1)
return W[0];
// CONTINUO DOPO
for(int i = 0; i < M; i++){
if(i){
if(abs(A[i-1][0] - A[i][0]) <= 1){
if(i >= 2){
dp[i][1] = memo[i-2] + A[i][2];
dp[i][0] = dp[i][1];
}
dp[i][1] = max(dp[i-1][0] + A[i][2], dp[i][1]);
}else{
dp[i][0] = memo[i-1] + A[i][2];
dp[i][1] = dp[i][0];
}
}else
dp[i][1] = A[i][2];
memo[i] = max(memo[i-1], max(dp[i][0], dp[i][1]));
}
if(A[M-1][0] == N-1){
ans = max(memo[M-2], dp[M-1][0]);
}else ans = memo[M-1];
return ans;
}
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
27 ms |
2132 KB |
Output is correct |
2 |
Correct |
28 ms |
4100 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
106 ms |
12132 KB |
Output is correct |
6 |
Correct |
90 ms |
12108 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
71 ms |
7308 KB |
Output is correct |
3 |
Correct |
89 ms |
11384 KB |
Output is correct |
4 |
Correct |
29 ms |
3340 KB |
Output is correct |
5 |
Correct |
34 ms |
4068 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
44 ms |
4928 KB |
Output is correct |
13 |
Correct |
45 ms |
5676 KB |
Output is correct |
14 |
Correct |
36 ms |
4972 KB |
Output is correct |
15 |
Correct |
43 ms |
5332 KB |
Output is correct |
16 |
Correct |
38 ms |
4980 KB |
Output is correct |
17 |
Correct |
41 ms |
5384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
20 ms |
3644 KB |
Output is correct |
4 |
Correct |
14 ms |
2912 KB |
Output is correct |
5 |
Incorrect |
36 ms |
6588 KB |
1st lines differ - on the 1st token, expected: '1673106170551', found: '1673110383290' |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
1st lines differ - on the 1st token, expected: '3', found: '0' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
1st lines differ - on the 1st token, expected: '3', found: '0' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
1st lines differ - on the 1st token, expected: '3', found: '0' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
20 ms |
3644 KB |
Output is correct |
4 |
Correct |
14 ms |
2912 KB |
Output is correct |
5 |
Incorrect |
36 ms |
6588 KB |
1st lines differ - on the 1st token, expected: '1673106170551', found: '1673110383290' |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
27 ms |
2132 KB |
Output is correct |
2 |
Correct |
28 ms |
4100 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
106 ms |
12132 KB |
Output is correct |
6 |
Correct |
90 ms |
12108 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
71 ms |
7308 KB |
Output is correct |
9 |
Correct |
89 ms |
11384 KB |
Output is correct |
10 |
Correct |
29 ms |
3340 KB |
Output is correct |
11 |
Correct |
34 ms |
4068 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
44 ms |
4928 KB |
Output is correct |
19 |
Correct |
45 ms |
5676 KB |
Output is correct |
20 |
Correct |
36 ms |
4972 KB |
Output is correct |
21 |
Correct |
43 ms |
5332 KB |
Output is correct |
22 |
Correct |
38 ms |
4980 KB |
Output is correct |
23 |
Correct |
41 ms |
5384 KB |
Output is correct |
24 |
Correct |
0 ms |
212 KB |
Output is correct |
25 |
Correct |
0 ms |
212 KB |
Output is correct |
26 |
Correct |
20 ms |
3644 KB |
Output is correct |
27 |
Correct |
14 ms |
2912 KB |
Output is correct |
28 |
Incorrect |
36 ms |
6588 KB |
1st lines differ - on the 1st token, expected: '1673106170551', found: '1673110383290' |
29 |
Halted |
0 ms |
0 KB |
- |