Submission #646987

# Submission time Handle Problem Language Result Execution time Memory
646987 2022-10-01T09:54:55 Z nandonathaniel K blocks (IZhO14_blocks) C++14
Compilation error
0 ms 0 KB
#include<bits/stdc++.h>
using namespace std;
const int MAXK=105,MAXN=100005;
long long dp[MAXK][MAXN],a[MAXN];
typedef pair<int,int> pii;
 
//https://codeforces.com/blog/entry/18866
 
int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int N,K;
	cin >> N >> K;
	for(int i=1;i<=N;i++)cin >> a[i];
	for(int i=1;i<=N;i++)dp[1][i]=max(dp[1][i-1],a[i]);
	for(int i=2;i<=K;i++){
		stack<pii> st;
		for(int j=i;j<=N;j++){
			long long minDP=1e18;
			while(!st.empty() && a[st.top().first]<=a[j]){
				minDP=st.top().second;
				st.pop();
			}
			int val=1e9;
			if(!st.empty())val=dp[i][st.top().first];
			dp[i][j]=min(val,minDP+a[j]);
			st.push({j,minDP});
		}
	}
	cout << dp[K][N] << '\n';
	return 0;
}

Compilation message

blocks.cpp: In function 'int main()':
blocks.cpp:25:31: error: no matching function for call to 'min(int&, long long int)'
   25 |    dp[i][j]=min(val,minDP+a[j]);
      |                               ^
In file included from /usr/include/c++/10/bits/char_traits.h:39,
                 from /usr/include/c++/10/ios:40,
                 from /usr/include/c++/10/istream:38,
                 from /usr/include/c++/10/sstream:38,
                 from /usr/include/c++/10/complex:45,
                 from /usr/include/c++/10/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:54,
                 from blocks.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:
blocks.cpp:25:31: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'long long int')
   25 |    dp[i][j]=min(val,minDP+a[j]);
      |                               ^
In file included from /usr/include/c++/10/bits/char_traits.h:39,
                 from /usr/include/c++/10/ios:40,
                 from /usr/include/c++/10/istream:38,
                 from /usr/include/c++/10/sstream:38,
                 from /usr/include/c++/10/complex:45,
                 from /usr/include/c++/10/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:54,
                 from blocks.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:
blocks.cpp:25:31: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'long long int')
   25 |    dp[i][j]=min(val,minDP+a[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 blocks.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:
blocks.cpp:25:31: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   25 |    dp[i][j]=min(val,minDP+a[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 blocks.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:
blocks.cpp:25:31: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   25 |    dp[i][j]=min(val,minDP+a[j]);
      |                               ^