답안 #883039

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
883039 2023-12-04T12:41:06 Z vjudge1 Growing Vegetable is Fun 3 (JOI19_ho_t3) C++14
컴파일 오류
0 ms 0 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int inf = 1e9 + 7;
inline int eval(int x , int y){
	return max(0 , x-y);
}
inline void ckmin(int &x , int y){
	x = min(x,y);
}
void solve(){
	int n;
	cin >> n;
	string str;
	cin >> str;
	vector < int > ind[3];
	for(int i = 0;i<n;i++){
		if(str[i] == 'R')ind[0].push_back(i);
		else if(str[i] == 'G')ind[1].push_back(i);
		else ind[2].push_back(i);
	}
	int dp[ind[0].size()+2][ind[1].size()+2][ind[2].size()+2][3];
	for(int i = 0;i<=ind[0].size();i++){
		for(int j = 0;j<=ind[1].size();j++){
			for(int k = 0;k<=ind[2].size();k++){
				dp[i][j][k][0] = dp[i][j][k][1] = dp[i][j][k][2] = inf;
			}
		}
	}
	dp[0][0][0][0] = 0;
	for(int cnt0 = 0;cnt0 <= (int)ind[0].size();cnt0++){
		for(int cnt1 = 0;cnt1 <= (int)ind[1].size();cnt1++){
			for(int cnt2 = 0;cnt2 <= (int)ind[2].size();cnt2++){
				if(cnt0 != (int)ind[0].size()){
					if(cnt0 == 0 and cnt1 == 0 and cnt2 == 0){
						ckmin(dp[cnt0+1][cnt1][cnt2][0] , dp[cnt0][cnt1][cnt2][0] + eval(ind[0][cnt0] , cnt0+cnt1+cnt2));
					}
					ckmin(dp[cnt0+1][cnt1][cnt2][0] , dp[cnt0][cnt1][cnt2][1] + eval(ind[0][cnt0] , cnt0+cnt1+cnt2));
					ckmin(dp[cnt0+1][cnt1][cnt2][0] , dp[cnt0][cnt1][cnt2][2] + eval(ind[0][cnt0] , cnt0+cnt1+cnt2));
				}
				if(cnt1 != (int)ind[1].size()){
					ckmin(dp[cnt0][cnt1+1][cnt2][1] , dp[cnt0][cnt1][cnt2][0] + eval(ind[1][cnt1] , cnt0+cnt1+cnt2));
					if(cnt0 == 0 and cnt1 == 0 and cnt2 == 0){
						ckmin(dp[cnt0][cnt1+1][cnt2][1] , dp[cnt0][cnt1][cnt2][1] + eval(ind[1][cnt1] , cnt0+cnt1+cnt2));
					}
					ckmin(dp[cnt0][cnt1+1][cnt2][1] , dp[cnt0][cnt1][cnt2][2] + eval(ind[1][cnt1] , cnt0+cnt1+cnt2));
				}
				if(cnt2 != (int)ind[2].size()){
					ckmin(dp[cnt0][cnt1][cnt2+1][2] , dp[cnt0][cnt1][cnt2][0] + eval(ind[2][cnt2] , cnt0+cnt1+cnt2));
					ckmin(dp[cnt0][cnt1][cnt2+1][2] , dp[cnt0][cnt1][cnt2][1] + eval(ind[2][cnt2] , cnt0+cnt1+cnt2));
					if(cnt0 == 0 and cnt1 == 0 and cnt2 == 0){
						ckmin(dp[cnt0][cnt1][cnt2+1][2] , dp[cnt0][cnt1][cnt2][2] + eval(ind[2][cnt2] , cnt0+cnt1+cnt2));
					}
				}
			}
		}
	}
	int ans = inf;
	for(int i = 0;i<3;i++){
		ans = min(ans , dp[ind[0].size()][ind[1].size()][ind[2].size()][i]);
	}
	cout << (ans == inf ? -1 : ans) << endl;
}
signed main(){
	ios_base::sync_with_stdio(0);cin.tie(0);
	int testcase = 1;//cin >> testcase;
	while(testcase--)solve();
}

Compilation message

joi2019_ho_t3.cpp: In function 'long long int eval(long long int, long long int)':
joi2019_ho_t3.cpp:6:20: error: no matching function for call to 'max(int, long long int)'
    6 |  return max(0 , x-y);
      |                    ^
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 joi2019_ho_t3.cpp:1:
/usr/include/c++/10/bits/stl_algobase.h:254:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  254 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/10/bits/stl_algobase.h:254:5: note:   template argument deduction/substitution failed:
joi2019_ho_t3.cpp:6:20: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'long long int')
    6 |  return max(0 , x-y);
      |                    ^
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 joi2019_ho_t3.cpp:1:
/usr/include/c++/10/bits/stl_algobase.h:300:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  300 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/10/bits/stl_algobase.h:300:5: note:   template argument deduction/substitution failed:
joi2019_ho_t3.cpp:6:20: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'long long int')
    6 |  return max(0 , x-y);
      |                    ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from joi2019_ho_t3.cpp:1:
/usr/include/c++/10/bits/stl_algo.h:3480:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(std::initializer_list<_Tp>)'
 3480 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3480:5: note:   template argument deduction/substitution failed:
joi2019_ho_t3.cpp:6:20: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
    6 |  return max(0 , x-y);
      |                    ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from joi2019_ho_t3.cpp:1:
/usr/include/c++/10/bits/stl_algo.h:3486:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(std::initializer_list<_Tp>, _Compare)'
 3486 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3486:5: note:   template argument deduction/substitution failed:
joi2019_ho_t3.cpp:6:20: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
    6 |  return max(0 , x-y);
      |                    ^
joi2019_ho_t3.cpp: In function 'void solve()':
joi2019_ho_t3.cpp:23:17: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   23 |  for(int i = 0;i<=ind[0].size();i++){
      |                ~^~~~~~~~~~~~~~~
joi2019_ho_t3.cpp:24:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   24 |   for(int j = 0;j<=ind[1].size();j++){
      |                 ~^~~~~~~~~~~~~~~
joi2019_ho_t3.cpp:25:19: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   25 |    for(int k = 0;k<=ind[2].size();k++){
      |                  ~^~~~~~~~~~~~~~~