307525: CF1368H1. Breadboard Capacity (easy version)

Memory Limit:512 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Breadboard Capacity (easy version)

题意翻译

## 题目描述 **本题与 [[CF1368H2] Breadboard Capacity (hard version)](https://www.luogu.com.cn/problem/CF1368H2) 的在于,本题中 $q=0$,即不存在修改操作。** 你有一块 $n\times m$ 的格子状空白电路板,它有 $n$ 行 $m$ 列。每一行和每一列的交点上有一个节点。在电路板的左右两侧各有 $n$ 个接口,上下两侧各有 $m$ 个接口。每个接口可以被连接到一个相邻的节点上。每个接口各是红色或者蓝色。*这里的相邻指上下左右方向上的第一个。* 下面给出了一个电路板的例子: ![Empty breadboard](https://cdn.luogu.com.cn/upload/vjudge_pic/CF1368H1/892efbe6be2ecb5cf3c218155cbe1684041ffb4a.png) 接口可以由电路板内部的电线来连接。这里有一些规则: - 每一条电线必须连接两个异色接口。一个接口最多由一条电线连接。 - 任何一部分电线必须是水平或者竖直的,且只能在节点处拐弯。 - 为了避免信号干扰,任意两条电线之间不能有公共的线路部分,但是可以经过公共节点。且一条电线不能重复覆盖一条有长度的线段。 我们定义这块电路板的容量为遵循以上连接规则后,红接口和蓝接口的最大连接数。例如,上图所示的电路板的容量为 $7$ ,一种连接方法请见下图: ![Possible connection](https://cdn.luogu.com.cn/upload/vjudge_pic/CF1368H1/c54dfbe0d7502b7f366741129332f0a68552a265.png) 给定一块电路的状况,请找出它的容量。 ## 输入格式 第一行包含三个整数 $n,m,q(1\le n,m\le 10^5, \bold{q=0})$。$n,m$ 表示电路板的长和宽。在这个问题中 $q$ 总是 0,你可以不管它。 第二行输入一个长 $n$ 的字符串,描述了从上到下的左侧接口的颜色。 第三行输入一个长 $n$ 的字符串,描述了从上到下的右侧接口的颜色。 第四行输入一个长 $m$ 的字符串,描述了从左到右的上侧接口的颜色。 第五行输入一个长 $m$ 的字符串,描述了从左到右的下侧接口的颜色。 所有字符串均以 ```R``` 表示红色,```B``` 表示蓝色。 ## 输出格式 输出一个整数,表示电路板的容量。

题目描述

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. ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF1368H1/892efbe6be2ecb5cf3c218155cbe1684041ffb4a.png)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. ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF1368H1/c54dfbe0d7502b7f366741129332f0a68552a265.png) 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.

输入输出格式

输入格式


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.

输出格式


Print a single integer — the given breadboard capacity.

输入输出样例

输入样例 #1

4 5 0
BBRR
RBBR
BBBBB
RRRRR

输出样例 #1

7

Input

题意翻译

## 题目描述 **本题与 [[CF1368H2] Breadboard Capacity (hard version)](https://www.luogu.com.cn/problem/CF1368H2) 的在于,本题中 $q=0$,即不存在修改操作。** 你有一块 $n\times m$ 的格子状空白电路板,它有 $n$ 行 $m$ 列。每一行和每一列的交点上有一个节点。在电路板的左右两侧各有 $n$ 个接口,上下两侧各有 $m$ 个接口。每个接口可以被连接到一个相邻的节点上。每个接口各是红色或者蓝色。*这里的相邻指上下左右方向上的第一个。* 下面给出了一个电路板的例子: ![Empty breadboard](https://cdn.luogu.com.cn/upload/vjudge_pic/CF1368H1/892efbe6be2ecb5cf3c218155cbe1684041ffb4a.png) 接口可以由电路板内部的电线来连接。这里有一些规则: - 每一条电线必须连接两个异色接口。一个接口最多由一条电线连接。 - 任何一部分电线必须是水平或者竖直的,且只能在节点处拐弯。 - 为了避免信号干扰,任意两条电线之间不能有公共的线路部分,但是可以经过公共节点。且一条电线不能重复覆盖一条有长度的线段。 我们定义这块电路板的容量为遵循以上连接规则后,红接口和蓝接口的最大连接数。例如,上图所示的电路板的容量为 $7$ ,一种连接方法请见下图: ![Possible connection](https://cdn.luogu.com.cn/upload/vjudge_pic/CF1368H1/c54dfbe0d7502b7f366741129332f0a68552a265.png) 给定一块电路的状况,请找出它的容量。 ## 输入格式 第一行包含三个整数 $n,m,q(1\le n,m\le 10^5, \bold{q=0})$。$n,m$ 表示电路板的长和宽。在这个问题中 $q$ 总是 0,你可以不管它。 第二行输入一个长 $n$ 的字符串,描述了从上到下的左侧接口的颜色。 第三行输入一个长 $n$ 的字符串,描述了从上到下的右侧接口的颜色。 第四行输入一个长 $m$ 的字符串,描述了从左到右的上侧接口的颜色。 第五行输入一个长 $m$ 的字符串,描述了从左到右的下侧接口的颜色。 所有字符串均以 ```R``` 表示红色,```B``` 表示蓝色。 ## 输出格式 输出一个整数,表示电路板的容量。

加入题单

算法标签: