Submission #676302

# Submission time Handle Problem Language Result Execution time Memory
676302 2022-12-30T08:34:07 Z penguin133 Safety (NOI18_safety) C++17
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define pi pair<int, int>
#define pii pair<int, pi>
#define fi first
#define se second
#define getchar_unlocked _getchar_nolock

int n, h, S[300005];

int dp[5005][5005];
deque<pi>dq;
void solve(){
	cin >> n >> h;
	for(int i=1;i<=n;i++)cin >> S[i];
	for(int i=0;i<=5000;i++)dp[1][i] = abs(S[1] - i);
	for(int i=2;i<=n;i++){
		dq.clear();
		for(int j=0;j<=min(5000, h);j++){
			while(!dq.empty() && dq.back().fi > dp[i-1][j])dq.pop_back();
			dq.push_back({dp[i-1][j], j});
		}
		for(int j=0;j<=5000;j++){
			if(!dq.empty() && dq.front().se < j - h)dq.pop_front();
			pi tmp = dq.front();
			dp[i][j] = tmp.fi + abs(S[i] - j);
			if(j + h + 1 <= 5000){
				while(!dq.empty() && dq.back().fi > dp[i-1][j + h + 1])dq.pop_back();
				dq.push_back({dp[i-1][j+h+1], j+h+1});
			}
		}
	}
	int ans = 1e18;
	for(int i=0;i<=5000;i++)ans = min(ans, dp[n][i]);
	cout << ans;
}

main(){
	ios::sync_with_stdio(0);cin.tie(0);
	int tc = 1;
	//cin >> tc;
	while(tc--){
		solve();
	}
}

Compilation message

safety.cpp: In function 'void solve()':
safety.cpp:21:29: error: no matching function for call to 'min(int, long long int&)'
   21 |   for(int j=0;j<=min(5000, h);j++){
      |                             ^
In file included from /usr/include/c++/10/bits/specfun.h:45,
                 from /usr/include/c++/10/cmath:1927,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:41,
                 from safety.cpp:1:
/usr/include/c++/10/bits/stl_algobase.h:230:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
  230 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/10/bits/stl_algobase.h:230:5: note:   template argument deduction/substitution failed:
safety.cpp:21:29: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'long long int')
   21 |   for(int j=0;j<=min(5000, h);j++){
      |                             ^
In file included from /usr/include/c++/10/bits/specfun.h:45,
                 from /usr/include/c++/10/cmath:1927,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:41,
                 from safety.cpp:1:
/usr/include/c++/10/bits/stl_algobase.h:278:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
  278 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/10/bits/stl_algobase.h:278:5: note:   template argument deduction/substitution failed:
safety.cpp:21:29: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'long long int')
   21 |   for(int j=0;j<=min(5000, h);j++){
      |                             ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from safety.cpp:1:
/usr/include/c++/10/bits/stl_algo.h:3468:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(std::initializer_list<_Tp>)'
 3468 |     min(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3468:5: note:   template argument deduction/substitution failed:
safety.cpp:21:29: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   21 |   for(int j=0;j<=min(5000, h);j++){
      |                             ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from safety.cpp:1:
/usr/include/c++/10/bits/stl_algo.h:3474:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(std::initializer_list<_Tp>, _Compare)'
 3474 |     min(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3474:5: note:   template argument deduction/substitution failed:
safety.cpp:21:29: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   21 |   for(int j=0;j<=min(5000, h);j++){
      |                             ^
safety.cpp: At global scope:
safety.cpp:40:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   40 | main(){
      | ^~~~