Codeforces Global Round 8
H1
Breadboard Capacity (easy version)
Codeforces
3300
原题
← GH2 →
翻译中…

This is an easier version of the problem H without modification queries.

翻译中…

Lester and Delbert work at an electronics company. They are currently working on a microchip component serving to connect two independent parts of a large supercomputer.

翻译中…

The component is built on top of a breadboard — a grid-like base for a microchip. The breadboard has $n$ rows and $m$ columns, and each row-column intersection contains a node. Also, on each side of the breadboard there are ports that can be attached to adjacent nodes. Left and right side have $n$ ports each, and top and bottom side have $m$ ports each. Each of the ports is connected on the outside to one of the parts bridged by the breadboard, and is colored red or blue respectively.

翻译中…

image

翻译中…

Ports can be connected by wires going inside the breadboard. However, there are a few rules to follow:

翻译中…
  • Each wire should connect a red port with a blue port, and each port should be connected to at most one wire.
  • Each part of the wire should be horizontal or vertical, and turns are only possible at one of the nodes.
  • To avoid interference, wires can not have common parts of non-zero length (but may have common nodes). Also, a wire can not cover the same segment of non-zero length twice.
翻译中…

The capacity of the breadboard is the largest number of red-blue wire connections that can be made subject to the rules above. For example, the breadboard above has capacity $7$, and one way to make seven connections is pictured below.

翻译中…

image

翻译中…

Up to this point statements of both versions are identical. Differences follow below.

翻译中…

Given the current breadboard configuration, help Lester and Delbert find its capacity efficiently.

翻译中…

Input

翻译中…

The first line contains three integers $n, m, q$ ($1 \leq n, m \leq 10^5$, $\pmb{q = 0}$). $n$ and $m$ are the number of rows and columns of the breadboard respectively. In this version $q$ is always zero, and is only present for consistency with the harder version.

翻译中…

The next four lines describe initial coloring of the ports. Each character in these lines is either R or B, depending on the coloring of the respective port. The first two of these lines contain $n$ characters each, and describe ports on the left and right sides respectively from top to bottom. The last two lines contain $m$ characters each, and describe ports on the top and bottom sides respectively from left to right.

翻译中…

Output

翻译中…

Print a single integer — the given breadboard capacity.

翻译中…

样例

Input #1
4 5 0
BBRR
RBBR
BBBBB
RRRRR
Output #1
7
InputCopy OutputCopy
题目信息
题号
1368H1
时间限制
2 s
内存限制
512 MB
标签
动态规划
网络流
贪心

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。