답안 #478560

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
478560 2021-10-08T01:47:14 Z Mackerel_Pike Growing Vegetable is Fun 3 (JOI19_ho_t3) C++14
100 / 100
101 ms 4176 KB
#include <bits/stdc++.h>

using namespace std;

const int maxn = 405;

int n;
int a[3][maxn], b[maxn][3], cnt[3];
int f[2][maxn][maxn][3];
char s[maxn];

inline int calc(int i, int j, int k, int l){
  return max(j - b[i][0], 0) + max(k - b[i][1], 0) + max(l - b[i][2], 0);
}

int main(){
  //freopen("b.in", "r", stdin);
  //freopen("b.out", "w", stdout);
  
  scanf("%d", &n);
  scanf("%s", s);


  for(int i = 0; i < n; ++i){
    for(int j = 0; j < 3; ++j)
      b[i][j] = cnt[j];
    s[i] = (s[i] == 'R' ? 2 : (s[i] == 'G'));
    a[s[i]][cnt[s[i]]++] = i;
  }

  int p = 0, q = 1;
  memset(f[p], 0x3f, sizeof(f[p]));
  if(cnt[0])
    f[p][1][0][0] = 0;
  if(cnt[1])
    f[p][0][1][1] = 0;
  if(cnt[2])
    f[p][0][0][2] = 0;
  for(int i = 1; i <= n - 1; ++i){
    memset(f[q], 0x3f, sizeof(f[q]));
    for(int j = 0; j <= i; ++j)
      for(int k = 0; k <= i - j; ++k){
	int l = i - j - k;
	for(int s = 0; s < 3; ++s)
	  if(f[p][j][k][s] != 0x3f3f3f3f){
	    if(s != 0 && j + 1 <= cnt[0])
	      f[q][j + 1][k][0] = min(f[q][j + 1][k][0], f[p][j][k][s] + calc(a[0][j], j, k, l));
	    if(s != 1 && k + 1 <= cnt[1])
	      f[q][j][k + 1][1] = min(f[q][j][k + 1][1], f[p][j][k][s] + calc(a[1][k], j, k, l));
	    if(s != 2 && l + 1 <= cnt[2])
	      f[q][j][k][2]     = min(f[q][j][k][2]    , f[p][j][k][s] + calc(a[2][l], j, k, l));
	  }
      }
    swap(p, q);
  }

  int ans = 0x3f3f3f3f;
  for(int i = 0; i < 3; ++i)
    ans = min(ans, f[p][cnt[0]][cnt[1]][i]);

  printf("%d\n", ans == 0x3f3f3f3f ? -1 : ans);
  return 0;
}

Compilation message

joi2019_ho_t3.cpp: In function 'int main()':
joi2019_ho_t3.cpp:28:10: warning: array subscript has type 'char' [-Wchar-subscripts]
   28 |     a[s[i]][cnt[s[i]]++] = i;
      |       ~~~^
joi2019_ho_t3.cpp:28:20: warning: array subscript has type 'char' [-Wchar-subscripts]
   28 |     a[s[i]][cnt[s[i]]++] = i;
      |                 ~~~^
joi2019_ho_t3.cpp:20:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   20 |   scanf("%d", &n);
      |   ~~~~~^~~~~~~~~~
joi2019_ho_t3.cpp:21:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   21 |   scanf("%s", s);
      |   ~~~~~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2128 KB Output is correct
2 Correct 3 ms 4048 KB Output is correct
3 Correct 2 ms 4048 KB Output is correct
4 Correct 3 ms 4048 KB Output is correct
5 Correct 4 ms 4048 KB Output is correct
6 Correct 3 ms 4048 KB Output is correct
7 Correct 4 ms 4048 KB Output is correct
8 Correct 4 ms 4128 KB Output is correct
9 Correct 4 ms 4048 KB Output is correct
10 Correct 3 ms 4048 KB Output is correct
11 Correct 3 ms 4048 KB Output is correct
12 Correct 3 ms 4148 KB Output is correct
13 Correct 3 ms 4048 KB Output is correct
14 Correct 3 ms 4048 KB Output is correct
15 Correct 3 ms 4048 KB Output is correct
16 Correct 3 ms 4048 KB Output is correct
17 Correct 3 ms 4048 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2128 KB Output is correct
2 Correct 3 ms 4048 KB Output is correct
3 Correct 2 ms 4048 KB Output is correct
4 Correct 3 ms 4048 KB Output is correct
5 Correct 4 ms 4048 KB Output is correct
6 Correct 3 ms 4048 KB Output is correct
7 Correct 4 ms 4048 KB Output is correct
8 Correct 4 ms 4128 KB Output is correct
9 Correct 4 ms 4048 KB Output is correct
10 Correct 3 ms 4048 KB Output is correct
11 Correct 3 ms 4048 KB Output is correct
12 Correct 3 ms 4148 KB Output is correct
13 Correct 3 ms 4048 KB Output is correct
14 Correct 3 ms 4048 KB Output is correct
15 Correct 3 ms 4048 KB Output is correct
16 Correct 3 ms 4048 KB Output is correct
17 Correct 3 ms 4048 KB Output is correct
18 Correct 6 ms 4048 KB Output is correct
19 Correct 8 ms 4144 KB Output is correct
20 Correct 6 ms 4048 KB Output is correct
21 Correct 6 ms 4048 KB Output is correct
22 Correct 7 ms 4176 KB Output is correct
23 Correct 6 ms 4152 KB Output is correct
24 Correct 6 ms 4048 KB Output is correct
25 Correct 6 ms 4048 KB Output is correct
26 Correct 5 ms 4176 KB Output is correct
27 Correct 5 ms 4060 KB Output is correct
28 Correct 10 ms 4160 KB Output is correct
29 Correct 6 ms 4176 KB Output is correct
30 Correct 7 ms 4152 KB Output is correct
31 Correct 8 ms 4060 KB Output is correct
32 Correct 9 ms 4060 KB Output is correct
33 Correct 8 ms 4172 KB Output is correct
34 Correct 6 ms 4060 KB Output is correct
35 Correct 8 ms 4084 KB Output is correct
36 Correct 5 ms 4104 KB Output is correct
37 Correct 5 ms 4060 KB Output is correct
38 Correct 7 ms 4056 KB Output is correct
39 Correct 5 ms 4060 KB Output is correct
40 Correct 6 ms 4060 KB Output is correct
41 Correct 6 ms 4060 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4156 KB Output is correct
2 Correct 78 ms 4060 KB Output is correct
3 Correct 78 ms 4152 KB Output is correct
4 Correct 80 ms 4132 KB Output is correct
5 Correct 69 ms 4148 KB Output is correct
6 Correct 70 ms 4136 KB Output is correct
7 Correct 66 ms 4160 KB Output is correct
8 Correct 73 ms 4152 KB Output is correct
9 Correct 69 ms 4048 KB Output is correct
10 Correct 79 ms 4048 KB Output is correct
11 Correct 77 ms 4112 KB Output is correct
12 Correct 21 ms 4152 KB Output is correct
13 Correct 36 ms 4144 KB Output is correct
14 Correct 61 ms 4132 KB Output is correct
15 Correct 69 ms 4148 KB Output is correct
16 Correct 74 ms 4136 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2128 KB Output is correct
2 Correct 3 ms 4048 KB Output is correct
3 Correct 2 ms 4048 KB Output is correct
4 Correct 3 ms 4048 KB Output is correct
5 Correct 4 ms 4048 KB Output is correct
6 Correct 3 ms 4048 KB Output is correct
7 Correct 4 ms 4048 KB Output is correct
8 Correct 4 ms 4128 KB Output is correct
9 Correct 4 ms 4048 KB Output is correct
10 Correct 3 ms 4048 KB Output is correct
11 Correct 3 ms 4048 KB Output is correct
12 Correct 3 ms 4148 KB Output is correct
13 Correct 3 ms 4048 KB Output is correct
14 Correct 3 ms 4048 KB Output is correct
15 Correct 3 ms 4048 KB Output is correct
16 Correct 3 ms 4048 KB Output is correct
17 Correct 3 ms 4048 KB Output is correct
18 Correct 6 ms 4048 KB Output is correct
19 Correct 8 ms 4144 KB Output is correct
20 Correct 6 ms 4048 KB Output is correct
21 Correct 6 ms 4048 KB Output is correct
22 Correct 7 ms 4176 KB Output is correct
23 Correct 6 ms 4152 KB Output is correct
24 Correct 6 ms 4048 KB Output is correct
25 Correct 6 ms 4048 KB Output is correct
26 Correct 5 ms 4176 KB Output is correct
27 Correct 5 ms 4060 KB Output is correct
28 Correct 10 ms 4160 KB Output is correct
29 Correct 6 ms 4176 KB Output is correct
30 Correct 7 ms 4152 KB Output is correct
31 Correct 8 ms 4060 KB Output is correct
32 Correct 9 ms 4060 KB Output is correct
33 Correct 8 ms 4172 KB Output is correct
34 Correct 6 ms 4060 KB Output is correct
35 Correct 8 ms 4084 KB Output is correct
36 Correct 5 ms 4104 KB Output is correct
37 Correct 5 ms 4060 KB Output is correct
38 Correct 7 ms 4056 KB Output is correct
39 Correct 5 ms 4060 KB Output is correct
40 Correct 6 ms 4060 KB Output is correct
41 Correct 6 ms 4060 KB Output is correct
42 Correct 2 ms 4156 KB Output is correct
43 Correct 78 ms 4060 KB Output is correct
44 Correct 78 ms 4152 KB Output is correct
45 Correct 80 ms 4132 KB Output is correct
46 Correct 69 ms 4148 KB Output is correct
47 Correct 70 ms 4136 KB Output is correct
48 Correct 66 ms 4160 KB Output is correct
49 Correct 73 ms 4152 KB Output is correct
50 Correct 69 ms 4048 KB Output is correct
51 Correct 79 ms 4048 KB Output is correct
52 Correct 77 ms 4112 KB Output is correct
53 Correct 21 ms 4152 KB Output is correct
54 Correct 36 ms 4144 KB Output is correct
55 Correct 61 ms 4132 KB Output is correct
56 Correct 69 ms 4148 KB Output is correct
57 Correct 74 ms 4136 KB Output is correct
58 Correct 91 ms 4132 KB Output is correct
59 Correct 100 ms 4048 KB Output is correct
60 Correct 100 ms 4136 KB Output is correct
61 Correct 101 ms 4168 KB Output is correct
62 Correct 69 ms 4156 KB Output is correct
63 Correct 66 ms 4048 KB Output is correct
64 Correct 72 ms 4144 KB Output is correct
65 Correct 77 ms 4136 KB Output is correct
66 Correct 82 ms 4048 KB Output is correct
67 Correct 94 ms 4168 KB Output is correct
68 Correct 91 ms 4136 KB Output is correct
69 Correct 97 ms 4048 KB Output is correct
70 Correct 91 ms 4048 KB Output is correct
71 Correct 85 ms 4152 KB Output is correct
72 Correct 64 ms 4168 KB Output is correct
73 Correct 76 ms 4048 KB Output is correct