Submission #109997

# Submission time Handle Problem Language Result Execution time Memory
109997 2019-05-08T15:06:50 Z Arturgo Growing Vegetable is Fun 3 (JOI19_ho_t3) C++14
100 / 100
197 ms 96120 KB
#include <iostream>
#include <algorithm>
#include <vector>
#include <array>
using namespace std;

int INFINI = 32000;
int nbPots;
string couleurs;

int ids[256];
vector<int> positions[3];
int nbAvant[3][401];
short dyn[401][401][401][3];

int main() {
  ios_base::sync_with_stdio(false);
  cin >> nbPots;
  cin >> couleurs;

  ids['R'] = 0;
  ids['G'] = 1;
  ids['Y'] = 2;

  for(int iPot = 0;iPot < nbPots;iPot++) {
    positions[ids[(int)couleurs[iPot]]].push_back(iPot);

    for(int iCouleur = 0;iCouleur < 3;iCouleur++) {
      nbAvant[iCouleur][iPot + 1] = nbAvant[iCouleur][iPot];
    }
    nbAvant[ids[(int)couleurs[iPot]]][iPot + 1]++;
  }

  for(int iR = 0;iR <= (int)positions[0].size();iR++) {
    for(int iG = 0;iG <= (int)positions[1].size();iG++) {
      for(int iY = 0;iY <= (int)positions[2].size();iY++) {
        for(int derCouleur = 0;derCouleur < 3;derCouleur++) {
	  dyn[iR][iG][iY][derCouleur] = INFINI;
	}
      }
    }
  }

  for(int derCouleur = 0;derCouleur < 3;derCouleur++) {
    dyn[0][0][0][derCouleur] = 0;
  }
  
  for(int iR = 0;iR <= (int)positions[0].size();iR++) {
    for(int iG = 0;iG <= (int)positions[1].size();iG++) {
      for(int iY = 0;iY <= (int)positions[2].size();iY++) {
	array<int, 3> curCouleur = {iR, iG, iY};

	for(int derCouleur = 0;derCouleur < 3;derCouleur++) {
	  for(int suivCouleur = 0;suivCouleur < 3;suivCouleur++) {
	    if(suivCouleur != derCouleur && curCouleur[suivCouleur] != (int)positions[suivCouleur].size()) {
	      array<int, 3> suiv = curCouleur;
	      suiv[suivCouleur]++;

	      int pos = positions[suivCouleur][curCouleur[suivCouleur]];

	      int nbDeps = max(0, nbAvant[0][pos] - curCouleur[0])
		+ max(0, nbAvant[1][pos] - curCouleur[1])
		+ max(0, nbAvant[2][pos] - curCouleur[2]);

	      dyn[suiv[0]][suiv[1]][suiv[2]][suivCouleur] = min<int>(
		dyn[suiv[0]][suiv[1]][suiv[2]][suivCouleur],
		dyn[iR][iG][iY][derCouleur] + nbDeps
	      );
	    }
	  }
	}
      }
    }
  }

  int mini = INFINI;
  for(int derCouleur = 0;derCouleur < 3;derCouleur++) {
    mini = min<int>(mini, dyn[positions[0].size()][positions[1].size()][positions[2].size()][derCouleur]);
  }

  if(mini == INFINI)
    cout << -1 << endl;
  else
    cout << mini << endl;
  return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 3 ms 384 KB Output is correct
5 Correct 3 ms 384 KB Output is correct
6 Correct 3 ms 512 KB Output is correct
7 Correct 3 ms 512 KB Output is correct
8 Correct 3 ms 512 KB Output is correct
9 Correct 2 ms 512 KB Output is correct
10 Correct 2 ms 640 KB Output is correct
11 Correct 2 ms 512 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 3 ms 384 KB Output is correct
14 Correct 2 ms 512 KB Output is correct
15 Correct 2 ms 384 KB Output is correct
16 Correct 2 ms 512 KB Output is correct
17 Correct 2 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 3 ms 384 KB Output is correct
5 Correct 3 ms 384 KB Output is correct
6 Correct 3 ms 512 KB Output is correct
7 Correct 3 ms 512 KB Output is correct
8 Correct 3 ms 512 KB Output is correct
9 Correct 2 ms 512 KB Output is correct
10 Correct 2 ms 640 KB Output is correct
11 Correct 2 ms 512 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 3 ms 384 KB Output is correct
14 Correct 2 ms 512 KB Output is correct
15 Correct 2 ms 384 KB Output is correct
16 Correct 2 ms 512 KB Output is correct
17 Correct 2 ms 384 KB Output is correct
18 Correct 4 ms 1536 KB Output is correct
19 Correct 3 ms 1280 KB Output is correct
20 Correct 3 ms 1408 KB Output is correct
21 Correct 3 ms 1536 KB Output is correct
22 Correct 4 ms 1152 KB Output is correct
23 Correct 3 ms 1408 KB Output is correct
24 Correct 3 ms 1024 KB Output is correct
25 Correct 5 ms 2560 KB Output is correct
26 Correct 5 ms 2688 KB Output is correct
27 Correct 5 ms 1920 KB Output is correct
28 Correct 3 ms 1536 KB Output is correct
29 Correct 4 ms 1408 KB Output is correct
30 Correct 4 ms 1536 KB Output is correct
31 Correct 4 ms 1280 KB Output is correct
32 Correct 3 ms 1536 KB Output is correct
33 Correct 4 ms 2432 KB Output is correct
34 Correct 4 ms 2304 KB Output is correct
35 Correct 3 ms 1664 KB Output is correct
36 Correct 3 ms 1280 KB Output is correct
37 Correct 3 ms 1152 KB Output is correct
38 Correct 4 ms 1408 KB Output is correct
39 Correct 4 ms 1536 KB Output is correct
40 Correct 4 ms 384 KB Output is correct
41 Correct 3 ms 1536 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 84 ms 96032 KB Output is correct
3 Correct 86 ms 95480 KB Output is correct
4 Correct 86 ms 96020 KB Output is correct
5 Correct 83 ms 95912 KB Output is correct
6 Correct 83 ms 96012 KB Output is correct
7 Correct 81 ms 95608 KB Output is correct
8 Correct 87 ms 95480 KB Output is correct
9 Correct 84 ms 94968 KB Output is correct
10 Correct 113 ms 96120 KB Output is correct
11 Correct 86 ms 96120 KB Output is correct
12 Correct 28 ms 26112 KB Output is correct
13 Correct 45 ms 45560 KB Output is correct
14 Correct 64 ms 65644 KB Output is correct
15 Correct 84 ms 95992 KB Output is correct
16 Correct 84 ms 95992 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 3 ms 384 KB Output is correct
5 Correct 3 ms 384 KB Output is correct
6 Correct 3 ms 512 KB Output is correct
7 Correct 3 ms 512 KB Output is correct
8 Correct 3 ms 512 KB Output is correct
9 Correct 2 ms 512 KB Output is correct
10 Correct 2 ms 640 KB Output is correct
11 Correct 2 ms 512 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 3 ms 384 KB Output is correct
14 Correct 2 ms 512 KB Output is correct
15 Correct 2 ms 384 KB Output is correct
16 Correct 2 ms 512 KB Output is correct
17 Correct 2 ms 384 KB Output is correct
18 Correct 4 ms 1536 KB Output is correct
19 Correct 3 ms 1280 KB Output is correct
20 Correct 3 ms 1408 KB Output is correct
21 Correct 3 ms 1536 KB Output is correct
22 Correct 4 ms 1152 KB Output is correct
23 Correct 3 ms 1408 KB Output is correct
24 Correct 3 ms 1024 KB Output is correct
25 Correct 5 ms 2560 KB Output is correct
26 Correct 5 ms 2688 KB Output is correct
27 Correct 5 ms 1920 KB Output is correct
28 Correct 3 ms 1536 KB Output is correct
29 Correct 4 ms 1408 KB Output is correct
30 Correct 4 ms 1536 KB Output is correct
31 Correct 4 ms 1280 KB Output is correct
32 Correct 3 ms 1536 KB Output is correct
33 Correct 4 ms 2432 KB Output is correct
34 Correct 4 ms 2304 KB Output is correct
35 Correct 3 ms 1664 KB Output is correct
36 Correct 3 ms 1280 KB Output is correct
37 Correct 3 ms 1152 KB Output is correct
38 Correct 4 ms 1408 KB Output is correct
39 Correct 4 ms 1536 KB Output is correct
40 Correct 4 ms 384 KB Output is correct
41 Correct 3 ms 1536 KB Output is correct
42 Correct 2 ms 384 KB Output is correct
43 Correct 84 ms 96032 KB Output is correct
44 Correct 86 ms 95480 KB Output is correct
45 Correct 86 ms 96020 KB Output is correct
46 Correct 83 ms 95912 KB Output is correct
47 Correct 83 ms 96012 KB Output is correct
48 Correct 81 ms 95608 KB Output is correct
49 Correct 87 ms 95480 KB Output is correct
50 Correct 84 ms 94968 KB Output is correct
51 Correct 113 ms 96120 KB Output is correct
52 Correct 86 ms 96120 KB Output is correct
53 Correct 28 ms 26112 KB Output is correct
54 Correct 45 ms 45560 KB Output is correct
55 Correct 64 ms 65644 KB Output is correct
56 Correct 84 ms 95992 KB Output is correct
57 Correct 84 ms 95992 KB Output is correct
58 Correct 178 ms 38108 KB Output is correct
59 Correct 175 ms 48376 KB Output is correct
60 Correct 195 ms 43896 KB Output is correct
61 Correct 153 ms 42412 KB Output is correct
62 Correct 101 ms 93560 KB Output is correct
63 Correct 102 ms 92280 KB Output is correct
64 Correct 139 ms 80504 KB Output is correct
65 Correct 180 ms 70204 KB Output is correct
66 Correct 197 ms 43224 KB Output is correct
67 Correct 177 ms 41592 KB Output is correct
68 Correct 154 ms 44408 KB Output is correct
69 Correct 157 ms 42836 KB Output is correct
70 Correct 154 ms 46372 KB Output is correct
71 Correct 193 ms 42232 KB Output is correct
72 Correct 56 ms 21376 KB Output is correct
73 Correct 11 ms 1664 KB Output is correct