Submission #627190

#TimeUsernameProblemLanguageResultExecution timeMemory
627190typ_ikCatfish Farm (IOI22_fish)C++17
3 / 100
82 ms7268 KiB
#include <bits/stdc++.h> #define all(x) (x).begin(), (x).end() using namespace std; long long max_weights(int N, int M, vector<int> X, vector<int> Y, vector<int> W) { int block1 = 0; for (auto c : X) block1 += (c & 1 ^ 1); if (block1 == M) return accumulate(all(W), 0ll); long long val[N + 1]; for (int i = 0; i <= N; i++) val[i] = 0; for (int i = 0; i < M; i++) val[X[i]] = W[i]; long long evenPref[N + 1], evenSuf[N + 1]; long long oddPref[N + 1], oddSuf[N + 1]; for (int i = 0; i <= N; i++) evenPref[i] = evenSuf[i] = oddPref[i] = oddSuf[i] = 0; evenPref[0] = val[0]; evenSuf[N - 1] = ((N - 1) & 1 ^ 1) * val[N - 1]; for (int i = 1; i < N; i++) { evenPref[i] = evenPref[i - 1]; if (i & 1 ^ 1) evenPref[i] += val[i]; } for (int i = N - 2; i >= 0; i--) { evenSuf[i] = evenSuf[i + 1]; if (i & 1 ^ 1) evenSuf[i] += val[i]; } for (int i = 1; i < N; i++) { oddPref[i] = oddPref[i - 1]; if (i & 1) oddPref[i] += val[i]; } oddSuf[N - 1] = ((N - 1) & 1) * val[N - 1]; for (int i = N - 2; i >= 0; i--) { oddSuf[i] = oddSuf[i + 1]; if (i & 1) oddSuf[i] += val[i]; } long long ans = max(evenPref[N - 1], oddPref[N - 1]); for (int i = 0; i < N; i++) { long long lEven = (i ? evenPref[i - 1] : 0); long long rOdd = oddSuf[i + 1]; ans = max(ans, lEven + rOdd); long long lOdd = (i ? oddPref[i - 1] : 0); long long rEven = evenSuf[i + 1]; ans = max(ans, lOdd + rEven); } return ans; } //main() { // int N = 10, M = 4; // vector <int> X = {0, 5, 7, 4}; // vector <int> Y = {0, 0, 0, 0}; // vector <int> W = {10, 5, 3, 6}; // cout << max_weights(N, M, X, Y, W) << '\n'; //}

Compilation message (stderr)

fish.cpp: In function 'long long int max_weights(int, int, std::vector<int>, std::vector<int>, std::vector<int>)':
fish.cpp:9:35: warning: suggest parentheses around arithmetic in operand of '^' [-Wparentheses]
    9 |     for (auto c : X) block1 += (c & 1 ^ 1);
      |                                 ~~^~~
fish.cpp:26:31: warning: suggest parentheses around arithmetic in operand of '^' [-Wparentheses]
   26 |     evenSuf[N - 1] = ((N - 1) & 1 ^ 1) * val[N - 1];
      |                       ~~~~~~~~^~~
fish.cpp:30:15: warning: suggest parentheses around arithmetic in operand of '^' [-Wparentheses]
   30 |         if (i & 1 ^ 1) evenPref[i] += val[i];
      |             ~~^~~
fish.cpp:35:15: warning: suggest parentheses around arithmetic in operand of '^' [-Wparentheses]
   35 |         if (i & 1 ^ 1) evenSuf[i] += val[i];
      |             ~~^~~
#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...