| 시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
|---|---|---|---|---|---|
| 1 초 | 512 MB | 34 | 14 | 11 | 36.667% |
There are 2N points on a circle numbered from 1 through 2N, in clockwise order. Each point is either white or black. There are N white points and N black points.
We will draw N line segments connecting these points so that the following conditions are satisfied.
Among the N line segments, the number of pairs of line segments intersecting each other is called the intersection number. Write a program which, given the information of the colors of the points, calculates the maximum of the intersection number when we draw N line segments.
Read the following data from the standard input.
N S
Here S is a string of length 2N representing the colors of the points. Each character of S is either B or W, and the i-th character (1 ≤ i ≤ 2N) is the color of the i-th point. It is B if the point is black, and W if the point is white.
Write one line to the standard output. The output should contain the maximum of the intersection number when we draw N line segments satisfying the conditions.
B and W. The character B appears N times in the string S, and the character W appears N times in the string S.| 번호 | 배점 | 제한 |
|---|---|---|
| 1 | 4 | N ≤ 8. |
| 2 | 21 | N ≤ 300. |
| 3 | 10 | N ≤ 2 000. |
| 4 | 65 | No additional constraints. |
3 BBWWBW
2
If we draw line segments as in the figure on the left, then the intersection number is 2. On the other hand, if we draw line segments as in the figure on the right, then the intersection number is 3, but the conditions in the task statement are not satisfied.
5 BWBWBBWBWW
8
10 WBBBWBBWWBWWBWWBWBWB
41
16 WWWBWBBBBWWBWWBWWBBWWBBBWBBBWWBW
105