Submission #254232

# Submission time Handle Problem Language Result Execution time Memory
254232 2020-07-29T15:11:51 Z amoo_safar Homecoming (BOI18_homecoming) C++14
Compilation error
0 ms 0 KB
// Null
#include <bits/stdc++.h>


#ifndef safar
#include "homecoming.h"
#endif

#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define debug(x) cerr << #x << " : " << x << '\n'

using namespace std;

typedef long long ll;

const int N = 2e6 + 10;
const ll Inf = 1e18;

ll dp[2][N];

ll solve(int n, int k, int *A, int *B){
	ll ans = 0;
	fill(dp[0], dp[0] + N, -Inf);
	fill(dp[1], dp[1] + N, -Inf);
	
	dp[0][0] = 0;
	ll Sm = B[0];
	for(int i = 1; i < n; i++){
		Sm += B[i];
		dp[0][i] = max(dp[0][i - 1], dp[1][i - 1]);
		if(i >= k){
			Sm -= B[i - k];
			dp[1][i] = max(dp[1][i - 1] - B[i] + A[i - k + 1], dp[0][i-k] + A[i - k + 1] - Sm);
		}
	}
	ans = max(ans, dp[0][n - 1] + dp[1][n - 1]);

	fill(dp[0], dp[0] + N, -Inf);
	fill(dp[1], dp[1] + N, -Inf);
	dp[1][0] = 0;

	Sm = 0;
	for(int i = 0; i < k; i++) Sm += A[(n - i) % n];

	for(int i = 1; i < n; i++){
		Sm += A[i];
		Sm -= A[(i - k + n) % n];

		dp[1][i] = max(dp[0][i - 1], dp[1][i - 1]);
		
		dp[0][i] = max(dp[0][i - 1] + B[i] - A[i], dp[1][i - 1] + B[i] - Sm);
	}
	ll S2 = 0;
	for(int i = 0; i < n; i++) S2 += A[i] - B[i];

	ans = max(ans, S2 + max(dp[0][n - 1], dp[1][n - 1]));
	ans = max(ans, S2);
	if(k == n){
		assert(ans == max(0, S2));
	}
	return ans;
}

#ifdef safar
int Ai[3] = {40, 80, 0}, Bi[3] = {140, 0, 20};
int main(){
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cout << solve(3, 2, Ai, Bi) << '\n';
	return 0;
}
#endif

Compilation message

In file included from /usr/include/c++/7/cassert:44:0,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:33,
                 from homecoming.cpp:2:
homecoming.cpp: In function 'll solve(int, int, int*, int*)':
homecoming.cpp:62:26: error: no matching function for call to 'max(int, ll&)'
   assert(ans == max(0, S2));
                          ^
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/istream:38,
                 from /usr/include/c++/7/sstream:38,
                 from /usr/include/c++/7/complex:45,
                 from /usr/include/c++/7/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:52,
                 from homecoming.cpp:2:
/usr/include/c++/7/bits/stl_algobase.h:219:5: note: candidate: template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)
     max(const _Tp& __a, const _Tp& __b)
     ^~~
/usr/include/c++/7/bits/stl_algobase.h:219:5: note:   template argument deduction/substitution failed:
In file included from /usr/include/c++/7/cassert:44:0,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:33,
                 from homecoming.cpp:2:
homecoming.cpp:62:26: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'll {aka long long int}')
   assert(ans == max(0, S2));
                          ^
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/istream:38,
                 from /usr/include/c++/7/sstream:38,
                 from /usr/include/c++/7/complex:45,
                 from /usr/include/c++/7/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:52,
                 from homecoming.cpp:2:
/usr/include/c++/7/bits/stl_algobase.h:265:5: note: candidate: template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)
     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
     ^~~
/usr/include/c++/7/bits/stl_algobase.h:265:5: note:   template argument deduction/substitution failed:
In file included from /usr/include/c++/7/cassert:44:0,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:33,
                 from homecoming.cpp:2:
homecoming.cpp:62:26: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'll {aka long long int}')
   assert(ans == max(0, S2));
                          ^
In file included from /usr/include/c++/7/algorithm:62:0,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:65,
                 from homecoming.cpp:2:
/usr/include/c++/7/bits/stl_algo.h:3462:5: note: candidate: template<class _Tp> constexpr _Tp std::max(std::initializer_list<_Tp>)
     max(initializer_list<_Tp> __l)
     ^~~
/usr/include/c++/7/bits/stl_algo.h:3462:5: note:   template argument deduction/substitution failed:
In file included from /usr/include/c++/7/cassert:44:0,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:33,
                 from homecoming.cpp:2:
homecoming.cpp:62:26: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   assert(ans == max(0, S2));
                          ^
In file included from /usr/include/c++/7/algorithm:62:0,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:65,
                 from homecoming.cpp:2:
/usr/include/c++/7/bits/stl_algo.h:3468:5: note: candidate: template<class _Tp, class _Compare> constexpr _Tp std::max(std::initializer_list<_Tp>, _Compare)
     max(initializer_list<_Tp> __l, _Compare __comp)
     ^~~
/usr/include/c++/7/bits/stl_algo.h:3468:5: note:   template argument deduction/substitution failed:
In file included from /usr/include/c++/7/cassert:44:0,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:33,
                 from homecoming.cpp:2:
homecoming.cpp:62:26: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   assert(ans == max(0, S2));
                          ^