#include <bits/stdc++.h>
using namespace std;
char S[444];
int dp[444][444][444][3];
int R[444], G[444], Y[444];
int n, r, g, y;
int main()
{
int i, j, k;
scanf("%d%s", &n, S);
for(i=0; i<n; i++){
if(S[i] == 'R') R[++r] = i;
else if(S[i] == 'G') G[++g] = i;
else Y[++y] = i;
}
for(i=0; i<=r; i++){
for(j=0; j<=g; j++){
for(k=0; k<=y; k++){
dp[i][j][k][0] = i? min(dp[i - 1][j][k][1], dp[i - 1][j][k][2]) + max(0, i + j + k - 1 - R[i]) : (i + j + k != 0) * 1e9;
dp[i][j][k][1] = j? min(dp[i][j - 1][k][2], dp[i][j - 1][k][0]) + max(0, i + j + k - 1 - G[j]) : (i + j + k != 0) * 1e9;
dp[i][j][k][2] = k? min(dp[i][j][k - 1][0], dp[i][j][k - 1][1]) + max(0, i + j + k - 1 - Y[k]) : (i + j + k != 0) * 1e9;
}
}
}
k = min(min(dp[r][g][y][0], dp[r][g][y][1]), dp[r][g][y][2]);
printf("%d\n", k < 1e9? k : -1);
return 0;
}
Compilation message
joi2019_ho_t3.cpp: In function 'int main()':
joi2019_ho_t3.cpp:14:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%s", &n, S);
~~~~~^~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
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 |
Incorrect |
2 ms |
512 KB |
Output isn't correct |
12 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
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 |
Incorrect |
2 ms |
512 KB |
Output isn't correct |
12 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
109 ms |
162808 KB |
Output is correct |
3 |
Correct |
109 ms |
161980 KB |
Output is correct |
4 |
Correct |
114 ms |
162892 KB |
Output is correct |
5 |
Correct |
111 ms |
162936 KB |
Output is correct |
6 |
Correct |
107 ms |
162780 KB |
Output is correct |
7 |
Correct |
107 ms |
162040 KB |
Output is correct |
8 |
Correct |
105 ms |
162004 KB |
Output is correct |
9 |
Correct |
109 ms |
161272 KB |
Output is correct |
10 |
Correct |
107 ms |
162920 KB |
Output is correct |
11 |
Correct |
106 ms |
162808 KB |
Output is correct |
12 |
Correct |
30 ms |
44060 KB |
Output is correct |
13 |
Correct |
51 ms |
77148 KB |
Output is correct |
14 |
Correct |
74 ms |
111224 KB |
Output is correct |
15 |
Correct |
108 ms |
162840 KB |
Output is correct |
16 |
Correct |
107 ms |
162808 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 |
Incorrect |
2 ms |
512 KB |
Output isn't correct |
12 |
Halted |
0 ms |
0 KB |
- |