Submission #626017

#TimeUsernameProblemLanguageResultExecution timeMemory
626017sword060Catfish Farm (IOI22_fish)C++17
9 / 100
120 ms11472 KiB
#include <bits/stdc++.h> #include "fish.h" using namespace std; long long max_weights(int x,int k,vector<int> a,vector<int> b,vector<int> c){ vector<pair<int,int>>l[2]; long long ans=0,cur=0,cur2=0; bool f=1; for(int i=0;i<k;i++){ l[a[i]%2].push_back({b[i],c[i]}); if(a[i]%2)cur+=c[i]; else cur2+=c[i]; f&=(b[i]==0); } if(f){ long long dp[x+1][2]; for(int i=0;i<x;i++)dp[i][0]=0,dp[i][1]=0; for(int i=0;i<k;i++)dp[a[i]][0]+=c[i],dp[a[i]][1]+=c[i]; dp[0][0]=-1e9;dp[x-1][1]=-1e9; for(int i=0;i<x;i++){ if(i>1)dp[i][1]+=max({0LL,dp[i-1][0],dp[i-2][1]}); else if(i>0)dp[i][1]+=max(0LL,dp[i-1][0]); if(i>2)dp[i][0]+=max({0LL,dp[i-2][0],dp[i-3][1]}); else if(i>1)dp[i][0]+=max({0LL,dp[i-2][0]}); ans=max({ans,dp[i][0],dp[i][1]}); } return ans; } sort(l[0].begin(),l[0].end()); sort(l[1].begin(),l[1].end()); ans=cur; if(x<=2){ return max(cur,cur2); } int j=0; for(int i=0;i<(int)l[0].size();i++){ cur+=l[0][i].second; while(j<l[1].size()&&l[1][j].first<=l[0][i].first){ cur-=l[1][j].second; j++; } ans=max(ans,cur); } return ans; }

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:37:12: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   37 |     while(j<l[1].size()&&l[1][j].first<=l[0][i].first){
      |           ~^~~~~~~~~~~~
#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...