Submission #171299

# Submission time Handle Problem Language Result Execution time Memory
171299 2019-12-28T08:53:05 Z dennisstar Growing Vegetable is Fun 3 (JOI19_ho_t3) C++11
100 / 100
222 ms 196768 KB
#include <bits/stdc++.h>
#define fi first
#define se second
#define ryan bear
#define now mem[co][r][g][y]
#define all(V) ((V).begin()), ((V).end())
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef long double ld;
typedef vector<int> vim;
typedef vector<ll> vlm;

int n, ar[410], mem[3][410][410][410], cnt[3][410];
char s[410];
vim c[3];

int f(int co, int r, int g, int y) {
	if (!(r+g+y)) return 0;
	if (now!=-1) return now;
	now=(1<<30);
	if (r&&co==0) now = min( now , min(f(1, r-1, g, y), f(2, r-1, g, y))+abs(g-cnt[1][c[0][r-1]])+abs(y-cnt[2][c[0][r-1]]));
	if (g&&co==1) now = min( now , min(f(0, r, g-1, y), f(2, r, g-1, y))+abs(r-cnt[0][c[1][g-1]])+abs(y-cnt[2][c[1][g-1]]));
	if (y&&co==2) now = min( now , min(f(0, r, g, y-1), f(1, r, g, y-1))+abs(r-cnt[0][c[2][y-1]])+abs(g-cnt[1][c[2][y-1]]));
	return now;
}

int main() {
	scanf("%d %s", &n, s);
	for (int i=1; i<=n; i++) ar[i]=(s[i-1]=='R'?0:(s[i-1]=='G'?1:2));
	for (int i=1; i<=n; i++) c[ar[i]].push_back(i);
	for (int i=1; i<=n; i++) {
		for (int j=0; j<3; j++) cnt[j][i]=cnt[j][i-1];
		cnt[ar[i]][i]++;
	}
	for (int i=0; i<3; i++) for (int j=0; j<=cnt[0][n]; j++) for (int k=0; k<=cnt[1][n]; k++) for (int l=0; l<=cnt[2][n]; l++) mem[i][j][k][l]=-1;
	int ans=(1<<30);
	for (int i=0; i<3; i++) if (c[i].size()) ans=min(ans, f(i, cnt[0][n], cnt[1][n], cnt[2][n]));
	if (ans==(1<<30)) {puts("-1"); return 0;}
	printf("%d\n", ans/2);
	return 0;
}

Compilation message

joi2019_ho_t3.cpp: In function 'int main()':
joi2019_ho_t3.cpp:30:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %s", &n, s);
  ~~~~~^~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 376 KB Output is correct
2 Correct 2 ms 400 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 504 KB Output is correct
5 Correct 2 ms 504 KB Output is correct
6 Correct 2 ms 632 KB Output is correct
7 Correct 2 ms 632 KB Output is correct
8 Correct 1 ms 632 KB Output is correct
9 Correct 2 ms 632 KB Output is correct
10 Correct 11 ms 760 KB Output is correct
11 Correct 2 ms 632 KB Output is correct
12 Correct 2 ms 504 KB Output is correct
13 Correct 2 ms 504 KB Output is correct
14 Correct 2 ms 632 KB Output is correct
15 Correct 2 ms 504 KB Output is correct
16 Correct 2 ms 632 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 376 KB Output is correct
2 Correct 2 ms 400 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 504 KB Output is correct
5 Correct 2 ms 504 KB Output is correct
6 Correct 2 ms 632 KB Output is correct
7 Correct 2 ms 632 KB Output is correct
8 Correct 1 ms 632 KB Output is correct
9 Correct 2 ms 632 KB Output is correct
10 Correct 11 ms 760 KB Output is correct
11 Correct 2 ms 632 KB Output is correct
12 Correct 2 ms 504 KB Output is correct
13 Correct 2 ms 504 KB Output is correct
14 Correct 2 ms 632 KB Output is correct
15 Correct 2 ms 504 KB Output is correct
16 Correct 2 ms 632 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 4 ms 2808 KB Output is correct
19 Correct 4 ms 2424 KB Output is correct
20 Correct 4 ms 2808 KB Output is correct
21 Correct 0 ms 2936 KB Output is correct
22 Correct 4 ms 2040 KB Output is correct
23 Correct 5 ms 2552 KB Output is correct
24 Correct 3 ms 1912 KB Output is correct
25 Correct 6 ms 4984 KB Output is correct
26 Correct 6 ms 5112 KB Output is correct
27 Correct 5 ms 3676 KB Output is correct
28 Correct 4 ms 2808 KB Output is correct
29 Correct 2 ms 2680 KB Output is correct
30 Correct 1 ms 2652 KB Output is correct
31 Correct 4 ms 2424 KB Output is correct
32 Correct 4 ms 2808 KB Output is correct
33 Correct 6 ms 4728 KB Output is correct
34 Correct 5 ms 4344 KB Output is correct
35 Correct 4 ms 3320 KB Output is correct
36 Correct 4 ms 2296 KB Output is correct
37 Correct 4 ms 2040 KB Output is correct
38 Correct 4 ms 2556 KB Output is correct
39 Correct 4 ms 2808 KB Output is correct
40 Correct 2 ms 376 KB Output is correct
41 Correct 4 ms 2680 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 152 ms 196760 KB Output is correct
3 Correct 153 ms 195704 KB Output is correct
4 Correct 153 ms 196720 KB Output is correct
5 Correct 160 ms 196748 KB Output is correct
6 Correct 152 ms 196632 KB Output is correct
7 Correct 150 ms 195704 KB Output is correct
8 Correct 153 ms 195728 KB Output is correct
9 Correct 152 ms 194680 KB Output is correct
10 Correct 160 ms 196768 KB Output is correct
11 Correct 150 ms 196628 KB Output is correct
12 Correct 43 ms 53384 KB Output is correct
13 Correct 73 ms 93416 KB Output is correct
14 Correct 105 ms 134596 KB Output is correct
15 Correct 153 ms 196644 KB Output is correct
16 Correct 151 ms 196676 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 376 KB Output is correct
2 Correct 2 ms 400 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 504 KB Output is correct
5 Correct 2 ms 504 KB Output is correct
6 Correct 2 ms 632 KB Output is correct
7 Correct 2 ms 632 KB Output is correct
8 Correct 1 ms 632 KB Output is correct
9 Correct 2 ms 632 KB Output is correct
10 Correct 11 ms 760 KB Output is correct
11 Correct 2 ms 632 KB Output is correct
12 Correct 2 ms 504 KB Output is correct
13 Correct 2 ms 504 KB Output is correct
14 Correct 2 ms 632 KB Output is correct
15 Correct 2 ms 504 KB Output is correct
16 Correct 2 ms 632 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 4 ms 2808 KB Output is correct
19 Correct 4 ms 2424 KB Output is correct
20 Correct 4 ms 2808 KB Output is correct
21 Correct 0 ms 2936 KB Output is correct
22 Correct 4 ms 2040 KB Output is correct
23 Correct 5 ms 2552 KB Output is correct
24 Correct 3 ms 1912 KB Output is correct
25 Correct 6 ms 4984 KB Output is correct
26 Correct 6 ms 5112 KB Output is correct
27 Correct 5 ms 3676 KB Output is correct
28 Correct 4 ms 2808 KB Output is correct
29 Correct 2 ms 2680 KB Output is correct
30 Correct 1 ms 2652 KB Output is correct
31 Correct 4 ms 2424 KB Output is correct
32 Correct 4 ms 2808 KB Output is correct
33 Correct 6 ms 4728 KB Output is correct
34 Correct 5 ms 4344 KB Output is correct
35 Correct 4 ms 3320 KB Output is correct
36 Correct 4 ms 2296 KB Output is correct
37 Correct 4 ms 2040 KB Output is correct
38 Correct 4 ms 2556 KB Output is correct
39 Correct 4 ms 2808 KB Output is correct
40 Correct 2 ms 376 KB Output is correct
41 Correct 4 ms 2680 KB Output is correct
42 Correct 2 ms 376 KB Output is correct
43 Correct 152 ms 196760 KB Output is correct
44 Correct 153 ms 195704 KB Output is correct
45 Correct 153 ms 196720 KB Output is correct
46 Correct 160 ms 196748 KB Output is correct
47 Correct 152 ms 196632 KB Output is correct
48 Correct 150 ms 195704 KB Output is correct
49 Correct 153 ms 195728 KB Output is correct
50 Correct 152 ms 194680 KB Output is correct
51 Correct 160 ms 196768 KB Output is correct
52 Correct 150 ms 196628 KB Output is correct
53 Correct 43 ms 53384 KB Output is correct
54 Correct 73 ms 93416 KB Output is correct
55 Correct 105 ms 134596 KB Output is correct
56 Correct 153 ms 196644 KB Output is correct
57 Correct 151 ms 196676 KB Output is correct
58 Correct 169 ms 78296 KB Output is correct
59 Correct 203 ms 99068 KB Output is correct
60 Correct 194 ms 90240 KB Output is correct
61 Correct 222 ms 87032 KB Output is correct
62 Correct 150 ms 191908 KB Output is correct
63 Correct 147 ms 189080 KB Output is correct
64 Correct 156 ms 165452 KB Output is correct
65 Correct 165 ms 143672 KB Output is correct
66 Correct 199 ms 88256 KB Output is correct
67 Correct 179 ms 84832 KB Output is correct
68 Correct 196 ms 91000 KB Output is correct
69 Correct 196 ms 87800 KB Output is correct
70 Correct 210 ms 94936 KB Output is correct
71 Correct 191 ms 86436 KB Output is correct
72 Correct 41 ms 44512 KB Output is correct
73 Correct 5 ms 2936 KB Output is correct