답안 #121072

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
121072 2019-06-26T04:43:13 Z 임유진(#2971) Growing Vegetable is Fun 3 (JOI19_ho_t3) C++14
100 / 100
126 ms 164904 KB
#include<stdio.h>
#include<algorithm>

using namespace std;

#define MAXN 405

const long long LINF=2123456789012345678ll;
char inp[MAXN];
int R[MAXN], G[MAXN], Y[MAXN], rn, gn, yn;
int rs[MAXN], gs[MAXN], ys[MAXN];
long long dp[MAXN][MAXN][MAXN][3];

void gmn(long long &x, long long y){
	x=min(x, y);
}

int main(){
	int N;
	long long ans=LINF;

	scanf("%d\n%s", &N, inp);

	for(int i=0; i<N; i++){
		if(inp[i]=='R') R[++rn]=i;
		if(inp[i]=='G') G[++gn]=i;
		if(inp[i]=='Y') Y[++yn]=i;
		rs[i]=rn;
		gs[i]=gn;
		ys[i]=yn;
	}

	//for(int i=0; i<N; i++) printf("%d ", rs[i]);

	for(int r=0; r<=rn; r++) for(int g=0; g<=gn; g++) for(int y=0; y<=yn; y++) for(int i=0; i<3; i++){
		//printf("[%d %d %d %d]\n", r, g, y, i);
		if(r+g+y==0) dp[r][g][y][i]=0ll;
		else{
			dp[r][g][y][i]=LINF;
			if(i==0&&r>0) gmn(dp[r][g][y][i], min(dp[r-1][g][y][1], dp[r-1][g][y][2])+max(0, gs[R[r]]-g)+max(0, ys[R[r]]-y));
			if(i==1&&g>0) gmn(dp[r][g][y][i], min(dp[r][g-1][y][0], dp[r][g-1][y][2])+max(0, rs[G[g]]-r)+max(0, ys[G[g]]-y));
			if(i==2&&y>0) gmn(dp[r][g][y][i], min(dp[r][g][y-1][0], dp[r][g][y-1][1])+max(0, rs[Y[y]]-r)+max(0, gs[Y[y]]-g));
		}
		//if(dp[r][g][y][i]==0ll) printf("dp[%d][%d][%d][%d]=%lld\n", r, g, y, i, dp[r][g][y][i]);
	}

	for(int i=0; i<3; i++) gmn(ans, dp[rn][gn][yn][i]);
	printf("%lld", ans==LINF?-1ll:ans);
	return 0;
}

Compilation message

joi2019_ho_t3.cpp: In function 'int main()':
joi2019_ho_t3.cpp:22:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d\n%s", &N, inp);
  ~~~~~^~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 512 KB Output is correct
6 Correct 2 ms 512 KB Output is correct
7 Correct 2 ms 512 KB Output is correct
8 Correct 2 ms 512 KB Output is correct
9 Correct 2 ms 640 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 512 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 2 ms 512 KB Output is correct
15 Correct 2 ms 512 KB Output is correct
16 Correct 2 ms 512 KB Output is correct
17 Correct 2 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 512 KB Output is correct
6 Correct 2 ms 512 KB Output is correct
7 Correct 2 ms 512 KB Output is correct
8 Correct 2 ms 512 KB Output is correct
9 Correct 2 ms 640 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 512 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 2 ms 512 KB Output is correct
15 Correct 2 ms 512 KB Output is correct
16 Correct 2 ms 512 KB Output is correct
17 Correct 2 ms 384 KB Output is correct
18 Correct 3 ms 2432 KB Output is correct
19 Correct 3 ms 2048 KB Output is correct
20 Correct 3 ms 2460 KB Output is correct
21 Correct 3 ms 2560 KB Output is correct
22 Correct 3 ms 1792 KB Output is correct
23 Correct 3 ms 2304 KB Output is correct
24 Correct 3 ms 1664 KB Output is correct
25 Correct 4 ms 4096 KB Output is correct
26 Correct 4 ms 4224 KB Output is correct
27 Correct 4 ms 3200 KB Output is correct
28 Correct 3 ms 2432 KB Output is correct
29 Correct 4 ms 2432 KB Output is correct
30 Correct 3 ms 2432 KB Output is correct
31 Correct 3 ms 2176 KB Output is correct
32 Correct 3 ms 2560 KB Output is correct
33 Correct 4 ms 3968 KB Output is correct
34 Correct 4 ms 3712 KB Output is correct
35 Correct 4 ms 2816 KB Output is correct
36 Correct 3 ms 2048 KB Output is correct
37 Correct 4 ms 1920 KB Output is correct
38 Correct 3 ms 2304 KB Output is correct
39 Correct 3 ms 2432 KB Output is correct
40 Correct 2 ms 384 KB Output is correct
41 Correct 3 ms 2304 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 110 ms 164060 KB Output is correct
3 Correct 107 ms 163320 KB Output is correct
4 Correct 113 ms 164072 KB Output is correct
5 Correct 118 ms 164124 KB Output is correct
6 Correct 115 ms 164060 KB Output is correct
7 Correct 111 ms 163260 KB Output is correct
8 Correct 111 ms 163176 KB Output is correct
9 Correct 112 ms 162400 KB Output is correct
10 Correct 113 ms 163984 KB Output is correct
11 Correct 112 ms 164220 KB Output is correct
12 Correct 31 ms 44404 KB Output is correct
13 Correct 53 ms 77688 KB Output is correct
14 Correct 76 ms 112120 KB Output is correct
15 Correct 108 ms 163960 KB Output is correct
16 Correct 108 ms 164088 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 512 KB Output is correct
6 Correct 2 ms 512 KB Output is correct
7 Correct 2 ms 512 KB Output is correct
8 Correct 2 ms 512 KB Output is correct
9 Correct 2 ms 640 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 512 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 2 ms 512 KB Output is correct
15 Correct 2 ms 512 KB Output is correct
16 Correct 2 ms 512 KB Output is correct
17 Correct 2 ms 384 KB Output is correct
18 Correct 3 ms 2432 KB Output is correct
19 Correct 3 ms 2048 KB Output is correct
20 Correct 3 ms 2460 KB Output is correct
21 Correct 3 ms 2560 KB Output is correct
22 Correct 3 ms 1792 KB Output is correct
23 Correct 3 ms 2304 KB Output is correct
24 Correct 3 ms 1664 KB Output is correct
25 Correct 4 ms 4096 KB Output is correct
26 Correct 4 ms 4224 KB Output is correct
27 Correct 4 ms 3200 KB Output is correct
28 Correct 3 ms 2432 KB Output is correct
29 Correct 4 ms 2432 KB Output is correct
30 Correct 3 ms 2432 KB Output is correct
31 Correct 3 ms 2176 KB Output is correct
32 Correct 3 ms 2560 KB Output is correct
33 Correct 4 ms 3968 KB Output is correct
34 Correct 4 ms 3712 KB Output is correct
35 Correct 4 ms 2816 KB Output is correct
36 Correct 3 ms 2048 KB Output is correct
37 Correct 4 ms 1920 KB Output is correct
38 Correct 3 ms 2304 KB Output is correct
39 Correct 3 ms 2432 KB Output is correct
40 Correct 2 ms 384 KB Output is correct
41 Correct 3 ms 2304 KB Output is correct
42 Correct 2 ms 384 KB Output is correct
43 Correct 110 ms 164060 KB Output is correct
44 Correct 107 ms 163320 KB Output is correct
45 Correct 113 ms 164072 KB Output is correct
46 Correct 118 ms 164124 KB Output is correct
47 Correct 115 ms 164060 KB Output is correct
48 Correct 111 ms 163260 KB Output is correct
49 Correct 111 ms 163176 KB Output is correct
50 Correct 112 ms 162400 KB Output is correct
51 Correct 113 ms 163984 KB Output is correct
52 Correct 112 ms 164220 KB Output is correct
53 Correct 31 ms 44404 KB Output is correct
54 Correct 53 ms 77688 KB Output is correct
55 Correct 76 ms 112120 KB Output is correct
56 Correct 108 ms 163960 KB Output is correct
57 Correct 108 ms 164088 KB Output is correct
58 Correct 105 ms 120640 KB Output is correct
59 Correct 120 ms 138004 KB Output is correct
60 Correct 112 ms 130032 KB Output is correct
61 Correct 115 ms 128296 KB Output is correct
62 Correct 112 ms 163704 KB Output is correct
63 Correct 114 ms 164904 KB Output is correct
64 Correct 120 ms 164600 KB Output is correct
65 Correct 126 ms 159096 KB Output is correct
66 Correct 113 ms 128376 KB Output is correct
67 Correct 106 ms 125660 KB Output is correct
68 Correct 113 ms 131396 KB Output is correct
69 Correct 110 ms 129012 KB Output is correct
70 Correct 114 ms 134904 KB Output is correct
71 Correct 107 ms 126288 KB Output is correct
72 Correct 41 ms 49692 KB Output is correct
73 Correct 7 ms 5504 KB Output is correct