제출 #768251

#제출 시각아이디문제언어결과실행 시간메모리
768251mousebeaver메기 농장 (IOI22_fish)C++17
3 / 100
1077 ms7284 KiB
#define ll long long #define pll pair<ll, ll> #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) { bool sub1 = true; bool sub2 = true; bool sub3 = true; for(ll i = 0; i < M; i++) { if(X[i] % 2 == 1) { sub1 = false; } if(X[i] > 1) { sub2 = false; } if(Y[i] != 0) { sub3 = false; } } if(sub1) { ll sum = 0; for(int i : W) { sum += (ll) i; } return sum; } if(sub2) { vector<pll> left(0); vector<pll> right(0); //height, weight ll sum0 = 0; ll sum1 = 1; for(ll i = 0; i < N; i++) { if(X[i] == 0) { left.push_back({Y[i], W[i]}); sum0 += W[i]; } else { right.push_back({Y[i], W[i]}); sum1 += W[i]; } } sort(left.begin(), left.end()); sort(right.begin(), right.end()); ll output = max(sum0, sum1); if(N > 2) { ll index0 = 0; ll index1 = 0; ll roof = right[index1].second; ll shadow = left[index0].second; while(index1 < (ll) right.size()) { while(index1 < (ll) right.size() && right[index1].first < left[index0].first) { index1++; roof += index1 < (ll) right.size() ? right[index1].second : 0; } if(index1 == (ll) right.size()) { break; } while(index0+1 < (ll)left.size() && left[index0+1].first <= right[index1].first) { index0++; shadow += left[index0].second; } output = max(output, shadow+sum1-roof); } index1++; roof += index1 < (ll) right.size() ? right[index1].second : 0; } return output; } if(sub3) { vector<ll> w(N, 0); for(ll i = 0; i < M; i++) { w[X[i]] = W[i]; } vector<vector<ll>> dp(N, vector<ll> (3, 0)); //Pier, no pier + uncaught, no pier + caught dp[0][2] = w[0]; for(ll i = 1; i < N; i++) { //Pier: dp[i][0] = dp[i-1][0]; dp[i][0] = max(dp[i][0], dp[i-1][1]+w[i-1]); dp[i][0] = max(dp[i][0], dp[i-1][2]); //no pier + uncaught: dp[i][1] = dp[i-1][1]; dp[i][1] = max(dp[i][1], dp[i-1][2]); //no pier + caught: dp[i][2] = dp[i-1][0]+w[i]; } return max(max(dp[N-1][0], dp[N-1][1]), dp[N-1][2]); } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...