Submission #99027

#TimeUsernameProblemLanguageResultExecution timeMemory
99027kriiiGrowing Vegetable is Fun 3 (JOI19_ho_t3)C++17
100 / 100
427 ms57336 KiB
#include <stdio.h>
#include <algorithm>
#include <vector>
using namespace std;

vector<int> pos[3];
int N; char S[404]; int T[404];
int X,C[3000000][3],D[3000000][3];

int tr(int i, int j, int k)
{
	return (i * (pos[1].size() + 1) + j) * (pos[2].size() + 1) + k;
}

int main()
{
	scanf ("%d",&N);
	scanf ("%s",S);
	for (int i=0;i<N;i++){
		if (S[i] == 'R') T[i] = 0;
		if (S[i] == 'G') T[i] = 1;
		if (S[i] == 'Y') T[i] = 2;
		pos[T[i]].push_back(i);
	}

	for (int i=0;i<=pos[0].size();i++) for (int j=0;j<=pos[1].size();j++) for (int k=0;k<=pos[2].size();k++){
		C[X][0] = i; C[X][1] = j; C[X][2] = k;
		D[X][0] = D[X][1] = D[X][2] = 0x7fffff;
		X++;
	}

	D[0][0] = D[0][1] = D[0][2] = 0;
	for (int x=0;x<X;x++){
		int c[3] = {C[x][0], C[x][1], C[x][2]};

		for (int k=0;k<3;k++) if (c[k] < pos[k].size()){
			int v = 0, u = pos[k][c[k]];
			for (int l=0;l<3;l++) if (l != k) v += pos[l].begin()+c[l] - upper_bound(pos[l].begin(),pos[l].begin()+c[l],u);

			c[k]++;
			int t = tr(c[0],c[1],c[2]);
			for (int l=0;l<3;l++) if (l != k){
				if (D[x][l] == 0x7fffff) continue;
				int d = D[x][l] + v;
				if (D[t][k] > d)
					D[t][k] = d;
			}
			c[k]--;
		}
	}

	int ans = min({D[X-1][0],D[X-1][1],D[X-1][2]});
	if (ans == 0x7fffff) ans = -1;
	printf ("%d\n",ans);

	return 0;
}

Compilation message (stderr)

joi2019_ho_t3.cpp: In function 'int main()':
joi2019_ho_t3.cpp:26:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i=0;i<=pos[0].size();i++) for (int j=0;j<=pos[1].size();j++) for (int k=0;k<=pos[2].size();k++){
               ~^~~~~~~~~~~~~~~
joi2019_ho_t3.cpp:26:51: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i=0;i<=pos[0].size();i++) for (int j=0;j<=pos[1].size();j++) for (int k=0;k<=pos[2].size();k++){
                                                  ~^~~~~~~~~~~~~~~
joi2019_ho_t3.cpp:26:86: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i=0;i<=pos[0].size();i++) for (int j=0;j<=pos[1].size();j++) for (int k=0;k<=pos[2].size();k++){
                                                                                     ~^~~~~~~~~~~~~~~
joi2019_ho_t3.cpp:36:34: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for (int k=0;k<3;k++) if (c[k] < pos[k].size()){
                             ~~~~~^~~~~~~~~~~~~~~
joi2019_ho_t3.cpp:17:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf ("%d",&N);
  ~~~~~~^~~~~~~~~
joi2019_ho_t3.cpp:18:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf ("%s",S);
  ~~~~~~^~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...