답안 #444205

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
444205 2021-07-13T11:04:53 Z nonsensenonsense1 Growing Vegetable is Fun 3 (JOI19_ho_t3) C++17
100 / 100
497 ms 757620 KB
#include <cstdio>
#include <algorithm>
#include <cstring>

const int INF = 0x3f3f3f3f;

const int N = 401;
int n, amt[3], pos[3][N], pr[3][N], d[N][N][N][3];
char s[N];

int f(int last) 
{
	int &cur = d[amt[0]][amt[1]][amt[2]][last];
	if (cur == -1) {
		cur = INF;
		if (!(amt[0] + amt[1] + amt[2])) cur = 0;
		else for (int i = 0; i < 3; ++i) if (i != last && amt[i]) {
			--amt[i];
			int inc = 0;
			for (int j = 0; j < 3; ++j) if (j != i) inc += std::max(0, pr[j][pos[i][amt[i]]] - amt[j]);
			cur = std::min(cur, f(i) + inc);
			++amt[i];
		}
	}
	return cur;
}

int main() 
{
	memset(***d, -1, N * N * N * 3 << 2);
	scanf("%d%s", &n, s);
	for (int i = 0; i < n; ++i) {
		int cur;
		if (s[i] == 'R') cur = 0;
		else if (s[i] == 'G') cur = 1;
		else cur = 2;
		pos[cur][amt[cur]++] = i;
		for (int j = 0; j < 3; ++j) {
			pr[j][i] += cur == j;
			if (i) pr[j][i] += pr[j][i - 1];
		}
	}
	int ans = INF;
	for (int i = 0; i < 3; ++i) ans = std::min(ans, f(i));
	if (ans == INF) printf("-1\n");
	else printf("%d\n", ans);
	return 0;
}

Compilation message

joi2019_ho_t3.cpp: In function 'int main()':
joi2019_ho_t3.cpp:31:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   31 |  scanf("%d%s", &n, s);
      |  ~~~~~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 337 ms 757312 KB Output is correct
2 Correct 332 ms 757448 KB Output is correct
3 Correct 333 ms 757316 KB Output is correct
4 Correct 333 ms 757480 KB Output is correct
5 Correct 335 ms 757620 KB Output is correct
6 Correct 331 ms 757268 KB Output is correct
7 Correct 328 ms 757316 KB Output is correct
8 Correct 328 ms 757372 KB Output is correct
9 Correct 326 ms 757316 KB Output is correct
10 Correct 342 ms 757300 KB Output is correct
11 Correct 331 ms 757376 KB Output is correct
12 Correct 334 ms 757336 KB Output is correct
13 Correct 334 ms 757392 KB Output is correct
14 Correct 333 ms 757364 KB Output is correct
15 Correct 333 ms 757344 KB Output is correct
16 Correct 329 ms 757328 KB Output is correct
17 Correct 337 ms 757316 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 337 ms 757312 KB Output is correct
2 Correct 332 ms 757448 KB Output is correct
3 Correct 333 ms 757316 KB Output is correct
4 Correct 333 ms 757480 KB Output is correct
5 Correct 335 ms 757620 KB Output is correct
6 Correct 331 ms 757268 KB Output is correct
7 Correct 328 ms 757316 KB Output is correct
8 Correct 328 ms 757372 KB Output is correct
9 Correct 326 ms 757316 KB Output is correct
10 Correct 342 ms 757300 KB Output is correct
11 Correct 331 ms 757376 KB Output is correct
12 Correct 334 ms 757336 KB Output is correct
13 Correct 334 ms 757392 KB Output is correct
14 Correct 333 ms 757364 KB Output is correct
15 Correct 333 ms 757344 KB Output is correct
16 Correct 329 ms 757328 KB Output is correct
17 Correct 337 ms 757316 KB Output is correct
18 Correct 352 ms 757348 KB Output is correct
19 Correct 328 ms 757376 KB Output is correct
20 Correct 336 ms 757284 KB Output is correct
21 Correct 334 ms 757368 KB Output is correct
22 Correct 333 ms 757444 KB Output is correct
23 Correct 333 ms 757316 KB Output is correct
24 Correct 335 ms 757340 KB Output is correct
25 Correct 339 ms 757276 KB Output is correct
26 Correct 336 ms 757296 KB Output is correct
27 Correct 329 ms 757288 KB Output is correct
28 Correct 332 ms 757584 KB Output is correct
29 Correct 339 ms 757424 KB Output is correct
30 Correct 335 ms 757328 KB Output is correct
31 Correct 330 ms 757280 KB Output is correct
32 Correct 343 ms 757316 KB Output is correct
33 Correct 330 ms 757404 KB Output is correct
34 Correct 337 ms 757372 KB Output is correct
35 Correct 337 ms 757380 KB Output is correct
36 Correct 335 ms 757304 KB Output is correct
37 Correct 330 ms 757384 KB Output is correct
38 Correct 332 ms 757264 KB Output is correct
39 Correct 331 ms 757336 KB Output is correct
40 Correct 329 ms 757360 KB Output is correct
41 Correct 330 ms 757300 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 342 ms 757312 KB Output is correct
2 Correct 340 ms 757472 KB Output is correct
3 Correct 355 ms 757364 KB Output is correct
4 Correct 344 ms 757316 KB Output is correct
5 Correct 340 ms 757440 KB Output is correct
6 Correct 332 ms 757316 KB Output is correct
7 Correct 329 ms 757312 KB Output is correct
8 Correct 337 ms 757456 KB Output is correct
9 Correct 330 ms 757304 KB Output is correct
10 Correct 333 ms 757312 KB Output is correct
11 Correct 361 ms 757392 KB Output is correct
12 Correct 335 ms 757388 KB Output is correct
13 Correct 335 ms 757320 KB Output is correct
14 Correct 335 ms 757444 KB Output is correct
15 Correct 336 ms 757520 KB Output is correct
16 Correct 337 ms 757316 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 337 ms 757312 KB Output is correct
2 Correct 332 ms 757448 KB Output is correct
3 Correct 333 ms 757316 KB Output is correct
4 Correct 333 ms 757480 KB Output is correct
5 Correct 335 ms 757620 KB Output is correct
6 Correct 331 ms 757268 KB Output is correct
7 Correct 328 ms 757316 KB Output is correct
8 Correct 328 ms 757372 KB Output is correct
9 Correct 326 ms 757316 KB Output is correct
10 Correct 342 ms 757300 KB Output is correct
11 Correct 331 ms 757376 KB Output is correct
12 Correct 334 ms 757336 KB Output is correct
13 Correct 334 ms 757392 KB Output is correct
14 Correct 333 ms 757364 KB Output is correct
15 Correct 333 ms 757344 KB Output is correct
16 Correct 329 ms 757328 KB Output is correct
17 Correct 337 ms 757316 KB Output is correct
18 Correct 352 ms 757348 KB Output is correct
19 Correct 328 ms 757376 KB Output is correct
20 Correct 336 ms 757284 KB Output is correct
21 Correct 334 ms 757368 KB Output is correct
22 Correct 333 ms 757444 KB Output is correct
23 Correct 333 ms 757316 KB Output is correct
24 Correct 335 ms 757340 KB Output is correct
25 Correct 339 ms 757276 KB Output is correct
26 Correct 336 ms 757296 KB Output is correct
27 Correct 329 ms 757288 KB Output is correct
28 Correct 332 ms 757584 KB Output is correct
29 Correct 339 ms 757424 KB Output is correct
30 Correct 335 ms 757328 KB Output is correct
31 Correct 330 ms 757280 KB Output is correct
32 Correct 343 ms 757316 KB Output is correct
33 Correct 330 ms 757404 KB Output is correct
34 Correct 337 ms 757372 KB Output is correct
35 Correct 337 ms 757380 KB Output is correct
36 Correct 335 ms 757304 KB Output is correct
37 Correct 330 ms 757384 KB Output is correct
38 Correct 332 ms 757264 KB Output is correct
39 Correct 331 ms 757336 KB Output is correct
40 Correct 329 ms 757360 KB Output is correct
41 Correct 330 ms 757300 KB Output is correct
42 Correct 342 ms 757312 KB Output is correct
43 Correct 340 ms 757472 KB Output is correct
44 Correct 355 ms 757364 KB Output is correct
45 Correct 344 ms 757316 KB Output is correct
46 Correct 340 ms 757440 KB Output is correct
47 Correct 332 ms 757316 KB Output is correct
48 Correct 329 ms 757312 KB Output is correct
49 Correct 337 ms 757456 KB Output is correct
50 Correct 330 ms 757304 KB Output is correct
51 Correct 333 ms 757312 KB Output is correct
52 Correct 361 ms 757392 KB Output is correct
53 Correct 335 ms 757388 KB Output is correct
54 Correct 335 ms 757320 KB Output is correct
55 Correct 335 ms 757444 KB Output is correct
56 Correct 336 ms 757520 KB Output is correct
57 Correct 337 ms 757316 KB Output is correct
58 Correct 489 ms 757316 KB Output is correct
59 Correct 477 ms 757364 KB Output is correct
60 Correct 480 ms 757408 KB Output is correct
61 Correct 497 ms 757416 KB Output is correct
62 Correct 333 ms 757444 KB Output is correct
63 Correct 333 ms 757408 KB Output is correct
64 Correct 369 ms 757400 KB Output is correct
65 Correct 392 ms 757352 KB Output is correct
66 Correct 478 ms 757420 KB Output is correct
67 Correct 460 ms 757424 KB Output is correct
68 Correct 493 ms 757416 KB Output is correct
69 Correct 489 ms 757416 KB Output is correct
70 Correct 487 ms 757528 KB Output is correct
71 Correct 470 ms 757316 KB Output is correct
72 Correct 341 ms 757328 KB Output is correct
73 Correct 335 ms 757368 KB Output is correct