Submission #155059

#TimeUsernameProblemLanguageResultExecution timeMemory
155059Charis02Homecoming (BOI18_homecoming)C++14
Compilation error
0 ms0 KiB
#include<iostream> #define ll long long #define rep(i,a,b) for(int i = a;i < b;i++) #define N 200003 #define INF 1e12 using namespace std; ll books[N],prize[N],sum[N]; ll dp[N][2]; const ll PASSED=1,NPASSED=0; ll get_sum(ll i,ll j) { if(i == 0) return sum[j]; return sum[j] - sum[i-1]; } ll solve(int n,int k,int A[],int B[]) { rep(i,0,n) { prize[i] = A[i]; books[i] = B[i]; if(i == 0) sum[i] = books[i]; else sum[i] = sum[i-1]+books[i]; } /* if you pass class i and class j and j-i < k it is optimal to pass all classes in between. */ // fix that class 0 is passed dp[0][PASSED] = prize[0] - get_sum(0,k-1); dp[0][NPASSED] = -INF; rep(i,1,n) { ll nextbook = i+k-1; // passed previous class ll cur = dp[i-1][PASSED]; if(nextbook < n) cur -= books[nextbook]; cur+=prize[i]; dp[i][PASSED] = cur; //didn't pass previous class cur = dp[i-1][NPASSED]; cur -= get_sum(i,min(n-1,nextbook)); // if we add stuff that is already in dp[i-1][NPASSED], then optimal answer isn't here since we could just pass class i-1 cur+=prize[i]; dp[i][PASSED] = max(dp[i][PASSED],cur); dp[i][NPASSED] = max(dp[i-1][NPASSED],dp[i-1][PASSED]); } ll ans = max(dp[n-1][PASSED],dp[n-1][NPASSED]); // fix that he didn't pass class 0 dp[0][NPASSED] = 0; dp[0][PASSED] = -INF; rep(i,1,n) { ll nextbook = (i+k-1)%n; // passed previous class ll cur = dp[i-1][PASSED]; cur -= books[nextbook]; cur+=prize[i]; dp[i][PASSED] = cur; //didn't pass previous class cur = dp[i-1][NPASSED]; if(nextbook < i) cur -= get_sum(i,n-1) + get_sum(0,nextbook); else cur -= get_sum(i,nextbook); cur+=prize[i]; dp[i][PASSED] = max(dp[i][PASSED],cur); dp[i][NPASSED] = max(dp[i-1][NPASSED],dp[i-1][PASSED]); } ans = max(ans,dp[n-1][PASSED]); ans = max(ans,dp[n-1][NPASSED]); return ans; }

Compilation message (stderr)

homecoming.cpp: In function 'long long int solve(int, int, int*, int*)':
homecoming.cpp:56:42: error: no matching function for call to 'min(int, long long int&)'
         cur -= get_sum(i,min(n-1,nextbook)); // if we add stuff that is already in dp[i-1][NPASSED], then optimal answer isn't here since we could just pass class i-1
                                          ^
In file included from /usr/include/c++/7/bits/char_traits.h:39:0,
                 from /usr/include/c++/7/ios:40,
                 from /usr/include/c++/7/ostream:38,
                 from /usr/include/c++/7/iostream:39,
                 from homecoming.cpp:1:
/usr/include/c++/7/bits/stl_algobase.h:195:5: note: candidate: template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)
     min(const _Tp& __a, const _Tp& __b)
     ^~~
/usr/include/c++/7/bits/stl_algobase.h:195:5: note:   template argument deduction/substitution failed:
homecoming.cpp:56:42: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'long long int')
         cur -= get_sum(i,min(n-1,nextbook)); // if we add stuff that is already in dp[i-1][NPASSED], then optimal answer isn't here since we could just pass class i-1
                                          ^
In file included from /usr/include/c++/7/bits/char_traits.h:39:0,
                 from /usr/include/c++/7/ios:40,
                 from /usr/include/c++/7/ostream:38,
                 from /usr/include/c++/7/iostream:39,
                 from homecoming.cpp:1:
/usr/include/c++/7/bits/stl_algobase.h:243:5: note: candidate: template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)
     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
     ^~~
/usr/include/c++/7/bits/stl_algobase.h:243:5: note:   template argument deduction/substitution failed:
homecoming.cpp:56:42: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'long long int')
         cur -= get_sum(i,min(n-1,nextbook)); // if we add stuff that is already in dp[i-1][NPASSED], then optimal answer isn't here since we could just pass class i-1
                                          ^