Submission #1273590

#TimeUsernameProblemLanguageResultExecution timeMemory
1273590trinm01Growing Vegetable is Fun 3 (JOI19_ho_t3)C++20
Compilation error
0 ms0 KiB
// #pragma GCC optimize("O3")
// #pragma GCC optimization("Ofast,unroll-loops")
// #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#include <bits/stdc++.h>
using namespace std;

#define int long long 
#define ll long long
#define FOR(i, l, r) for (int i = (l); i <= (r); i++)
#define FOD(i, r, l) for (int i = (r); i >= (l); i--)
#define fi first
#define se second
#define pii pair<int, int>

const ll mod = 1e9 + 9;
const int MAXN = 400 + 5;
const ll oo = 1e18 + 7;  
const int base = 10;

int n;
string s;
vector<int> pos[3];

int f[MAXN][MAXN][MAXN][3];
int dp(int j, int k, int t, int last){
	int i=j+k+t;
	if(i>n-1){
		return 0;
	}	
	if(f[j][k][t][last]!=-1){
		return f[j][k][t][last];
	}
	
	int ans=oo;
	if(i==0 || last!=0){
		if(j<=(int)pos[0].size()-1){
			ans=min(ans, dp(j+1, k, t, 0)+max(0, pos[0][j]-i));
		}
	}
	if(i==0 || last!=1){
		if(k<=(int)pos[1].size()-1){
			ans=min(ans, dp(j, k+1, t, 1)+max(0, pos[1][k]-i));
		}
	}
	if(i==0 || last!=2){
		if(t<=(int)pos[2].size()-1){
			ans=min(ans, dp(j, k, t+1, 2)+max(0, pos[2][t]-i));
		}
	}
	return f[j][k][t][last]=ans;
}

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    
	// freopen("test.txt", "r", stdin);
	// freopen("o2.out", "w", stdout);
	
	if(fopen(".inp", "r")){
	  freopen(".inp", "r", stdin);
	  freopen(".out", "w", stdout);
	}

	cin >> n >> s;
	FOR(i, 0, n-1){
		if(s[i]=='R'){
			pos[0].push_back(i);
		}
		else if(s[i]=='G'){
			pos[1].push_back(i);
		}
		else{
			pos[2].push_back(i);
		}
	}
	
	FOR(j, 0, (int)pos[0].size()+1){
		FOR(k, 0, (int)pos[1].size()+1){
			FOR(t, 0, (int)pos[2].size()+1){
				FOR(last, 0, 2){
					f[j][k][t][last]=-1;
				}
			}
		}
	}
	
	int ans=dp(0, 0, 0, 0);
	if(ans==oo){
		ans=-1;
	}
	cout << ans;
	// cout << f[0][0][0][0] << ' ';
	
    return 0;
}

Compilation message (stderr)

joi2019_ho_t3.cpp: In function 'long long int dp(long long int, long long int, long long int, long long int)':
joi2019_ho_t3.cpp:37:58: error: no matching function for call to 'max(int, __gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type)'
   37 |                         ans=min(ans, dp(j+1, k, t, 0)+max(0, pos[0][j]-i));
      |                                                       ~~~^~~~~~~~~~~~~~~~
In file included from /usr/include/c++/13/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:51,
                 from joi2019_ho_t3.cpp:4:
/usr/include/c++/13/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/13/bits/stl_algobase.h:257:5: note:   template argument deduction/substitution failed:
joi2019_ho_t3.cpp:37:58: note:   deduced conflicting types for parameter 'const _Tp' ('int' and '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'})
   37 |                         ans=min(ans, dp(j+1, k, t, 0)+max(0, pos[0][j]-i));
      |                                                       ~~~^~~~~~~~~~~~~~~~
/usr/include/c++/13/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/13/bits/stl_algobase.h:303:5: note:   template argument deduction/substitution failed:
joi2019_ho_t3.cpp:37:58: note:   deduced conflicting types for parameter 'const _Tp' ('int' and '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'})
   37 |                         ans=min(ans, dp(j+1, k, t, 0)+max(0, pos[0][j]-i));
      |                                                       ~~~^~~~~~~~~~~~~~~~
In file included from /usr/include/c++/13/algorithm:61:
/usr/include/c++/13/bits/stl_algo.h:5795:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
 5795 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/13/bits/stl_algo.h:5795:5: note:   template argument deduction/substitution failed:
joi2019_ho_t3.cpp:37:58: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   37 |                         ans=min(ans, dp(j+1, k, t, 0)+max(0, pos[0][j]-i));
      |                                                       ~~~^~~~~~~~~~~~~~~~
/usr/include/c++/13/bits/stl_algo.h:5805:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
 5805 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/13/bits/stl_algo.h:5805:5: note:   template argument deduction/substitution failed:
joi2019_ho_t3.cpp:37:58: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   37 |                         ans=min(ans, dp(j+1, k, t, 0)+max(0, pos[0][j]-i));
      |                                                       ~~~^~~~~~~~~~~~~~~~
joi2019_ho_t3.cpp:42:58: error: no matching function for call to 'max(int, __gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type)'
   42 |                         ans=min(ans, dp(j, k+1, t, 1)+max(0, pos[1][k]-i));
      |                                                       ~~~^~~~~~~~~~~~~~~~
/usr/include/c++/13/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/13/bits/stl_algobase.h:257:5: note:   template argument deduction/substitution failed:
joi2019_ho_t3.cpp:42:58: note:   deduced conflicting types for parameter 'const _Tp' ('int' and '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'})
   42 |                         ans=min(ans, dp(j, k+1, t, 1)+max(0, pos[1][k]-i));
      |                                                       ~~~^~~~~~~~~~~~~~~~
/usr/include/c++/13/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/13/bits/stl_algobase.h:303:5: note:   template argument deduction/substitution failed:
joi2019_ho_t3.cpp:42:58: note:   deduced conflicting types for parameter 'const _Tp' ('int' and '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'})
   42 |                         ans=min(ans, dp(j, k+1, t, 1)+max(0, pos[1][k]-i));
      |                                                       ~~~^~~~~~~~~~~~~~~~
/usr/include/c++/13/bits/stl_algo.h:5795:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
 5795 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/13/bits/stl_algo.h:5795:5: note:   template argument deduction/substitution failed:
joi2019_ho_t3.cpp:42:58: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   42 |                         ans=min(ans, dp(j, k+1, t, 1)+max(0, pos[1][k]-i));
      |                                                       ~~~^~~~~~~~~~~~~~~~
/usr/include/c++/13/bits/stl_algo.h:5805:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
 5805 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/13/bits/stl_algo.h:5805:5: note:   template argument deduction/substitution failed:
joi2019_ho_t3.cpp:42:58: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   42 |                         ans=min(ans, dp(j, k+1, t, 1)+max(0, pos[1][k]-i));
      |                                                       ~~~^~~~~~~~~~~~~~~~
joi2019_ho_t3.cpp:47:58: error: no matching function for call to 'max(int, __gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type)'
   47 |                         ans=min(ans, dp(j, k, t+1, 2)+max(0, pos[2][t]-i));
      |                                                       ~~~^~~~~~~~~~~~~~~~
/usr/include/c++/13/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/13/bits/stl_algobase.h:257:5: note:   template argument deduction/substitution failed:
joi2019_ho_t3.cpp:47:58: note:   deduced conflicting types for parameter 'const _Tp' ('int' and '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'})
   47 |                         ans=min(ans, dp(j, k, t+1, 2)+max(0, pos[2][t]-i));
      |                                                       ~~~^~~~~~~~~~~~~~~~
/usr/include/c++/13/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/13/bits/stl_algobase.h:303:5: note:   template argument deduction/substitution failed:
joi2019_ho_t3.cpp:47:58: note:   deduced conflicting types for parameter 'const _Tp' ('int' and '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'})
   47 |                         ans=min(ans, dp(j, k, t+1, 2)+max(0, pos[2][t]-i));
      |                                                       ~~~^~~~~~~~~~~~~~~~
/usr/include/c++/13/bits/stl_algo.h:5795:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
 5795 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/13/bits/stl_algo.h:5795:5: note:   template argument deduction/substitution failed:
joi2019_ho_t3.cpp:47:58: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   47 |                         ans=min(ans, dp(j, k, t+1, 2)+max(0, pos[2][t]-i));
      |                                                       ~~~^~~~~~~~~~~~~~~~
/usr/include/c++/13/bits/stl_algo.h:5805:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
 5805 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/13/bits/stl_algo.h:5805:5: note:   template argument deduction/substitution failed:
joi2019_ho_t3.cpp:47:58: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   47 |                         ans=min(ans, dp(j, k, t+1, 2)+max(0, pos[2][t]-i));
      |                                                       ~~~^~~~~~~~~~~~~~~~
joi2019_ho_t3.cpp: In function 'int main()':
joi2019_ho_t3.cpp:63:18: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   63 |           freopen(".inp", "r", stdin);
      |           ~~~~~~~^~~~~~~~~~~~~~~~~~~~
joi2019_ho_t3.cpp:64:18: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   64 |           freopen(".out", "w", stdout);
      |           ~~~~~~~^~~~~~~~~~~~~~~~~~~~~