# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
634375 | l_reho | Catfish Farm (IOI22_fish) | C++17 | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
vector<vector<int>> V;
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;
}