Submission #127619

# Submission time Handle Problem Language Result Execution time Memory
127619 2019-07-09T17:11:08 Z IOrtroiii Growing Vegetable is Fun 3 (JOI19_ho_t3) C++14
100 / 100
81 ms 31096 KB
#include <bits/stdc++.h>

using namespace std;

const int inf = 1e9;

char s[405];
int cnt[3];
int pref[405][3];
int where[405][3];
vector<vector<vector<int>>> f[3];

int conv(char c) {
   if (c == 'R') return 0;
   else if (c == 'G') return 1;
   return 2;
}

int main() {
   ios_base::sync_with_stdio(false);
   int n;
   scanf("%d %s", &n, s + 1);
   for (int i = 1; i <= n; ++i) {
      int t = conv(s[i]);
      where[++cnt[t]][t] = i;
      for (int j = 0; j < 3; ++j) {
         pref[i][j] = cnt[j];
      }
   }
   for (int i = 0; i < 3; ++i) {
      f[i].resize(cnt[0] + 1);
      for (auto& f2 : f[i]) {
         f2.resize(cnt[1] + 1);
         for (auto& f3 : f2) {
            f3.assign(cnt[2] + 1, inf);
         }
      }
   }
   f[0][0][0][0] = f[1][0][0][0] = f[2][0][0][0] = 0;
   for (int x = 0; x <= cnt[0]; ++x) {
      for (int y = 0; y <= cnt[1]; ++y) {
         for (int z = 0; z <= cnt[2]; ++z) {
            if (x < cnt[0]) {
               int cost = min(f[1][x][y][z], f[2][x][y][z]);
               int wh = where[x + 1][0];
               cost += max(0, y - pref[wh][1]) + max(0, z - pref[wh][2]);
               f[0][x + 1][y][z] = min(f[0][x + 1][y][z], cost);
            }
            if (y < cnt[1]) {
               int cost = min(f[0][x][y][z], f[2][x][y][z]);
               int wh = where[y + 1][1];
               cost += max(0, x - pref[wh][0]) + max(0, z - pref[wh][2]);
               f[1][x][y + 1][z] = min(f[1][x][y + 1][z], cost);
            }
            if (z < cnt[2]) {
               int cost = min(f[0][x][y][z], f[1][x][y][z]);
               int wh = where[z + 1][2];
               cost += max(0, x - pref[wh][0]) + max(0, y - pref[wh][1]);
               f[2][x][y][z + 1] = min(f[2][x][y][z + 1], cost);
            }
         }
      }
   }
   int ans = min({f[0][cnt[0]][cnt[1]][cnt[2]], f[1][cnt[0]][cnt[1]][cnt[2]], f[2][cnt[0]][cnt[1]][cnt[2]]});
   if (ans == inf) ans = -1;
   printf("%d\n", ans);
}

Compilation message

joi2019_ho_t3.cpp: In function 'int main()':
joi2019_ho_t3.cpp:22:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    scanf("%d %s", &n, s + 1);
    ~~~~~^~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 504 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 504 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 380 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 504 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 504 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 380 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 3 ms 504 KB Output is correct
19 Correct 3 ms 504 KB Output is correct
20 Correct 3 ms 504 KB Output is correct
21 Correct 3 ms 504 KB Output is correct
22 Correct 2 ms 504 KB Output is correct
23 Correct 3 ms 504 KB Output is correct
24 Correct 2 ms 504 KB Output is correct
25 Correct 2 ms 504 KB Output is correct
26 Correct 2 ms 504 KB Output is correct
27 Correct 2 ms 504 KB Output is correct
28 Correct 2 ms 504 KB Output is correct
29 Correct 2 ms 504 KB Output is correct
30 Correct 2 ms 476 KB Output is correct
31 Correct 2 ms 504 KB Output is correct
32 Correct 2 ms 504 KB Output is correct
33 Correct 2 ms 504 KB Output is correct
34 Correct 2 ms 504 KB Output is correct
35 Correct 2 ms 504 KB Output is correct
36 Correct 2 ms 504 KB Output is correct
37 Correct 3 ms 504 KB Output is correct
38 Correct 3 ms 504 KB Output is correct
39 Correct 2 ms 508 KB Output is correct
40 Correct 2 ms 376 KB Output is correct
41 Correct 2 ms 504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 14 ms 7032 KB Output is correct
3 Correct 13 ms 6904 KB Output is correct
4 Correct 13 ms 7036 KB Output is correct
5 Correct 13 ms 7032 KB Output is correct
6 Correct 13 ms 7032 KB Output is correct
7 Correct 13 ms 7032 KB Output is correct
8 Correct 13 ms 6904 KB Output is correct
9 Correct 13 ms 7000 KB Output is correct
10 Correct 13 ms 7032 KB Output is correct
11 Correct 13 ms 7032 KB Output is correct
12 Correct 5 ms 2168 KB Output is correct
13 Correct 7 ms 3448 KB Output is correct
14 Correct 10 ms 4856 KB Output is correct
15 Correct 13 ms 7032 KB Output is correct
16 Correct 13 ms 7032 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 504 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 504 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 380 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 3 ms 504 KB Output is correct
19 Correct 3 ms 504 KB Output is correct
20 Correct 3 ms 504 KB Output is correct
21 Correct 3 ms 504 KB Output is correct
22 Correct 2 ms 504 KB Output is correct
23 Correct 3 ms 504 KB Output is correct
24 Correct 2 ms 504 KB Output is correct
25 Correct 2 ms 504 KB Output is correct
26 Correct 2 ms 504 KB Output is correct
27 Correct 2 ms 504 KB Output is correct
28 Correct 2 ms 504 KB Output is correct
29 Correct 2 ms 504 KB Output is correct
30 Correct 2 ms 476 KB Output is correct
31 Correct 2 ms 504 KB Output is correct
32 Correct 2 ms 504 KB Output is correct
33 Correct 2 ms 504 KB Output is correct
34 Correct 2 ms 504 KB Output is correct
35 Correct 2 ms 504 KB Output is correct
36 Correct 2 ms 504 KB Output is correct
37 Correct 3 ms 504 KB Output is correct
38 Correct 3 ms 504 KB Output is correct
39 Correct 2 ms 508 KB Output is correct
40 Correct 2 ms 376 KB Output is correct
41 Correct 2 ms 504 KB Output is correct
42 Correct 2 ms 376 KB Output is correct
43 Correct 14 ms 7032 KB Output is correct
44 Correct 13 ms 6904 KB Output is correct
45 Correct 13 ms 7036 KB Output is correct
46 Correct 13 ms 7032 KB Output is correct
47 Correct 13 ms 7032 KB Output is correct
48 Correct 13 ms 7032 KB Output is correct
49 Correct 13 ms 6904 KB Output is correct
50 Correct 13 ms 7000 KB Output is correct
51 Correct 13 ms 7032 KB Output is correct
52 Correct 13 ms 7032 KB Output is correct
53 Correct 5 ms 2168 KB Output is correct
54 Correct 7 ms 3448 KB Output is correct
55 Correct 10 ms 4856 KB Output is correct
56 Correct 13 ms 7032 KB Output is correct
57 Correct 13 ms 7032 KB Output is correct
58 Correct 77 ms 30600 KB Output is correct
59 Correct 78 ms 31096 KB Output is correct
60 Correct 75 ms 30072 KB Output is correct
61 Correct 77 ms 30712 KB Output is correct
62 Correct 16 ms 6904 KB Output is correct
63 Correct 20 ms 8572 KB Output is correct
64 Correct 46 ms 18680 KB Output is correct
65 Correct 59 ms 23160 KB Output is correct
66 Correct 79 ms 30456 KB Output is correct
67 Correct 81 ms 30052 KB Output is correct
68 Correct 76 ms 30328 KB Output is correct
69 Correct 79 ms 30968 KB Output is correct
70 Correct 77 ms 30840 KB Output is correct
71 Correct 75 ms 30328 KB Output is correct
72 Correct 22 ms 8568 KB Output is correct
73 Correct 6 ms 2296 KB Output is correct