Submission #871722

#TimeUsernameProblemLanguageResultExecution timeMemory
871722NonozeCatfish Farm (IOI22_fish)C++17
18 / 100
207 ms42832 KiB
#include "fish.h" //include "grader.cpp" #include <bits/stdc++.h> using namespace std; #define int long long map<pair<int, pair<bool, bool>>, int> memo; vector<int> values; int n; int dp(int empl, bool take, bool pretake) { if (empl>=n) return 0; if (memo.count({empl, {take, pretake}})) return memo[{empl, {take, pretake}}]; int ans=dp(empl+1, false, take); int temp=dp(empl+1, true, take); if (!pretake && !take && empl>0) { temp+=values[empl-1]; } if (empl+1<n) temp+=values[empl+1]; if (take) temp-=values[empl]; return memo[{empl, {take, pretake}}]=max(ans, temp); } #undef int long long max_weights(int N, int m, vector<int> x, vector<int> y, vector<int> w) { #define int long long n=N; bool tacha=true, tachb=true, tachc=true; for (int i = 0; i < m; ++i) { if (x[i]%2) tacha=false; if (x[i]>1) tachb=false; if (y[i]) tachc=false; } if (tacha) { int ans=0; for (int i = 0; i < m; ++i) ans+=w[i]; return ans; } if (tachb) { vector<vector<int>> farm(2, vector<int> (n, 0)); for (int i=0; i<m; i++) { farm[x[i]][y[i]]=w[i]; } vector<int> suml, sumr; suml.push_back(farm[0][0]); sumr.push_back(farm[1][0]); for (int i=1; i<n; i++) { suml.push_back(suml.back()+farm[0][i]); sumr.push_back(sumr.back()+farm[1][i]); } if (n==2) return max(suml.back(), sumr.back()); int ans=sumr.back(); for (int i=0; i<n; i++) { ans=max(ans, suml[i]+sumr.back()-sumr[i]); } return ans; } values.resize(n); for (int i=0; i<m; i++) { values[x[i]]=w[i]; } return dp(0, false, false); #undef int }

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:29:31: warning: variable 'tachc' set but not used [-Wunused-but-set-variable]
   29 |  bool tacha=true, tachb=true, tachc=true;
      |                               ^~~~~
#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...