루미 알고리즘

#1543플래티넘Light show

PO 2022 온라인 예선코딩출제 Johan Sannemo영어 원문이 문제가 어렵다면 — 배우는 순서 보기

영어 원문입니다. 원문의 수식·표를 글자로 옮겨 모양이 다를 수 있습니다. 정확한 내용은 원문 페이지에서 확인하세요. 원문 페이지 열기 (새 창)

Problem

Your friend is designing a light show for the closing ceremony of this year's Programming Olympiad finals. The hall where the ceremony is held can be viewed as a grid with R rows and C columns. Different lamps are mounted along the four sides, which can shine in one of three different colors: red, blue, or green. During the ceremony, the idea is that the lamps will shift in different patterns.

(그림은 원문 저장소에서 볼 수 있습니다)

Figure 1: An example of a lamp color configuration, where R = C = 4. The example corresponds to the only test case in test group 1.

A lamp illuminates all the squares along the same column or row where it is mounted. If a certain square is illuminated by at least one lamp of each color, the light in the square will be perceived as an unpleasant glaring white. Your friend has already designed a draft of the light show and now wonders if some of the chosen light configurations cause too many squares to become white. To determine whether a configuration is okay or not, you have been tasked with writing a program that reads the color of all the lamps and calculates the number of squares that will shine white.

Input

The first line contains two integers R (1 ≤ R ≤ 10^6) and C (1 ≤ C ≤ 10^6), the number of rows and columns in the grid-shaped hall.

The next four lines each contain a text string describing the colors of all the lamps. The first line describes the C lamps at the top of the grid shining downwards in order from left to right, the second line describes the R lamps to the right of the grid shining to the left in order from top to bottom, the third line describes the C lamps below the grid shining upwards in order from left to right, the fourth line describes the R lamps to the left of the grid shining to the right in order from top to bottom.

The color of a lamp is described using the characters RGB depending on whether the lamp shines red, green, or blue.

Output

Print a single integer – the number of squares in the hall that shine white. Note: the answer does not necessarily fit in a 32-bit integer.

Scoring

Your solution will be tested on a set of test groups, each worth a number of points. Each test group contains a set of test cases. To get the points for a test group you need to solve all test cases in the test group.

GroupPointsConstraints
120The group consists of a single test case, the one on our poster (https://www.progolymp.se/2022/affisch.pdf).
215All lamps on the same side have the same color.
325R,C ≤ 1000
425All lamps to the right or left of the grid shine red, and all lamps above and below the grid shine green or blue.
515No additional constraints.

Explanation of Example Cases

In the first case, all squares in the only row are illuminated by red from both left and right. The first square is illuminated by green from both above and below, the second and fourth squares by both green and blue, while the third is only illuminated by blue. Thus, two of the squares are illuminated by all three colors and become white.

In the third example, blue light is completely absent. Therefore, no squares can be white.

예제

예제 1

입력
1 4
GGBB
R
GBBG
R
출력
2

예제 2

입력
1 1
R
G
B
R
출력
1

예제 3

입력
4 4
RRRR
GGGG
GGGG
RRRR
출력
0

예제 4

입력
4 4
RRGB
GBBR
GGGB
BRBR
출력
7

출처 표기

출처: Programmeringsolympiaden 2022년 온라인 예선 · 원문 페이지 · 이용 조건 CC BY-SA · LaTeX 원문을 화면용 글로 옮겼습니다(수식·표의 모양이 다를 수 있습니다). 내용은 고치지 않았습니다.

크리에이티브 커먼즈 저작자표시-동일조건변경허락.

문제 출처: 한국정보올림피아드(KOI) (CC BY-NC-SA 4.0) · International Olympiad in Informatics (IOI) (CC BY) · Centre for Education in Mathematics and Computing (CEMC), University of Waterloo (CC BY-NC 4.0) · Programmeringsolympiaden (CC BY-SA) · CSES Problem Set (Antti Laaksonen) (CC BY-NC-SA 4.0). 루미 알고리즘은 위 단체들과 관계없는 별도의 서비스이며, 자료는 원문 그대로 싣습니다. 문제마다 출처와 이용 조건을 따로 표기합니다.