Submission #884470

#TimeUsernameProblemLanguageResultExecution timeMemory
884470vjudge1Growing Vegetable is Fun 3 (JOI19_ho_t3)C++17
15 / 100
262 ms1017516 KiB
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define endl "\n"
#define all(aa) aa.begin(), aa.end()
const int INF=1e9;

int n;
vector<int> ind[3];
int dp[402][402][402][4];

int f(int a, int b, int c, char l){
	if(a+b+c==n) return 0;

	int &cur=dp[a][b][c][l];
	if(cur!=-1) return cur; 

	cur=INF;
	if(l==0){
		if(b!=ind[1].size()) cur=min(cur, f(a, b+1, c, 1)+max(0, ind[1][b]-(a+b+c)));
		if(c!=ind[2].size()) cur=min(cur, f(a, b, c+1, 2)+max(0, ind[2][c]-(a+b+c)));
	}
	else if(l==1){
		if(a!=ind[0].size()) cur=min(cur, f(a+1, b, c, 0)+max(0, ind[0][a]-(a+b+c)));
		if(c!=ind[2].size()) cur=min(cur, f(a, b, c+1, 2)+max(0, ind[2][c]-(a+b+c)));
	}
	else{
		if(b!=ind[1].size()) cur=min(cur, f(a, b+1, c, 1)+max(0, ind[1][b]-(a+b+c)));
		if(a!=ind[0].size()) cur=min(cur, f(a+1, b, c, 0)+max(0, ind[0][a]-(a+b+c)));
	}
	return cur;
}
int main(){
	string s;
	cin>>n>>s;

	memset(dp, -1, sizeof(dp));
	for(int i=0; i<n; i++){
		if(s[i]=='R')
			ind[0].push_back(i);
		else if(s[i]=='G')
			ind[1].push_back(i);
		else
			ind[2].push_back(i);
	}

	int ans=f(0, 0, 0, 3);
	cout<<(ans>=INF ? -1:ans)<<endl;
}

Compilation message (stderr)

joi2019_ho_t3.cpp: In function 'int f(int, int, int, char)':
joi2019_ho_t3.cpp:16:23: warning: array subscript has type 'char' [-Wchar-subscripts]
   16 |  int &cur=dp[a][b][c][l];
      |                       ^
joi2019_ho_t3.cpp:21:7: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   21 |   if(b!=ind[1].size()) cur=min(cur, f(a, b+1, c, 1)+max(0, ind[1][b]-(a+b+c)));
      |      ~^~~~~~~~~~~~~~~
joi2019_ho_t3.cpp:22:7: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   22 |   if(c!=ind[2].size()) cur=min(cur, f(a, b, c+1, 2)+max(0, ind[2][c]-(a+b+c)));
      |      ~^~~~~~~~~~~~~~~
joi2019_ho_t3.cpp:25:7: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   25 |   if(a!=ind[0].size()) cur=min(cur, f(a+1, b, c, 0)+max(0, ind[0][a]-(a+b+c)));
      |      ~^~~~~~~~~~~~~~~
joi2019_ho_t3.cpp:26:7: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   26 |   if(c!=ind[2].size()) cur=min(cur, f(a, b, c+1, 2)+max(0, ind[2][c]-(a+b+c)));
      |      ~^~~~~~~~~~~~~~~
joi2019_ho_t3.cpp:29:7: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   29 |   if(b!=ind[1].size()) cur=min(cur, f(a, b+1, c, 1)+max(0, ind[1][b]-(a+b+c)));
      |      ~^~~~~~~~~~~~~~~
joi2019_ho_t3.cpp:30:7: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   30 |   if(a!=ind[0].size()) cur=min(cur, f(a+1, b, c, 0)+max(0, ind[0][a]-(a+b+c)));
      |      ~^~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...