A15409 | Cleaning Robot
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Consider a hallway, which can be represented as the matrix with $2$ rows and $n$ columns. Let's denote the cell on the intersection of the $i$ -th row and the $j$ -th column as $(i, j)$ . The distance between the cells $(i_1, j_1)$ and $(i_2, j_2)$ is $|i_1 - i_2| + |j_1 - j_2|$ .
There is a cleaning robot in the cell $(1, 1)$ . Some cells of the hallway are clean, other cells are dirty (the cell with the robot is clean). You want to clean the hallway, so you are going to launch the robot to do this.
After the robot is launched, it works as follows. While at least one cell is dirty, the robot chooses the closest (to its current cell) cell among those which are dirty, moves there and cleans it (so the cell is no longer dirty). After cleaning a cell, the robot again finds the closest dirty cell to its current cell, and so on. This process repeats until the whole hallway is clean.
However, there is a critical bug in the robot's program. If at some moment, there are multiple closest (to the robot's current position) dirty cells, the robot malfunctions.
You want to clean the hallway in such a way that the robot doesn't malfunction. Before launching the robot, you can clean some (possibly zero) of the dirty cells yourself. However, you don't want to do too much dirty work yourself while you have this nice, smart (yet buggy) robot to do this. Note that you cannot make a clean cell dirty.
Calculate the maximum possible number of cells you can leave dirty before launching the robot, so that it doesn't malfunction.
There is a cleaning robot in the cell $(1, 1)$ . Some cells of the hallway are clean, other cells are dirty (the cell with the robot is clean). You want to clean the hallway, so you are going to launch the robot to do this.
After the robot is launched, it works as follows. While at least one cell is dirty, the robot chooses the closest (to its current cell) cell among those which are dirty, moves there and cleans it (so the cell is no longer dirty). After cleaning a cell, the robot again finds the closest dirty cell to its current cell, and so on. This process repeats until the whole hallway is clean.
However, there is a critical bug in the robot's program. If at some moment, there are multiple closest (to the robot's current position) dirty cells, the robot malfunctions.
You want to clean the hallway in such a way that the robot doesn't malfunction. Before launching the robot, you can clean some (possibly zero) of the dirty cells yourself. However, you don't want to do too much dirty work yourself while you have this nice, smart (yet buggy) robot to do this. Note that you cannot make a clean cell dirty.
Calculate the maximum possible number of cells you can leave dirty before launching the robot, so that it doesn't malfunction.
输入格式
The first line contains one integer $n$ ( $2 \le n \le 2 \cdot 10^5$ ) — the number of columns in the hallway.
Then two lines follow, denoting the $1$ -st and the $2$ -nd row of the hallway. These lines contain $n$ characters each, where 0 denotes a clean cell and 1 denotes a dirty cell. The starting cell of the robot $(1, 1)$ is clean.
Then two lines follow, denoting the $1$ -st and the $2$ -nd row of the hallway. These lines contain $n$ characters each, where 0 denotes a clean cell and 1 denotes a dirty cell. The starting cell of the robot $(1, 1)$ is clean.
输出格式
Print one integer — the maximum possible number of cells you can leave dirty before launching the robot, so that it doesn't malfunction.
输入输出样例
输入 #1
2 01 11
输出 #1
2
输入 #2
2 01 01
输出 #2
2
输入 #3
4 0101 1011
输出 #3
4
输入 #4
4 0000 0000
输出 #4
0
输入 #5
5 00011 10101
输出 #5
4
输入 #6
6 011111 111111
输出 #6
8
输入 #7
10 0101001010 1010100110
输出 #7
6
In the first example, you can clean the cell $(1, 2)$ , so the path of the robot is $(1, 1) \rightarrow (2, 1) \rightarrow (2, 2)$ .
In the second example, you can leave the hallway as it is, so the path of the robot is $(1, 1) \rightarrow (1, 2) \rightarrow (2, 2)$ .
In the third example, you can clean the cell $(1, 2)$ , so the path of the robot is $(1, 1) \rightarrow (2, 1) \rightarrow (2, 3) \rightarrow (2, 4) \rightarrow (1, 4)$ .
In the fourth example, the hallway is already clean. Maybe you have launched the robot earlier?
In the second example, you can leave the hallway as it is, so the path of the robot is $(1, 1) \rightarrow (1, 2) \rightarrow (2, 2)$ .
In the third example, you can clean the cell $(1, 2)$ , so the path of the robot is $(1, 1) \rightarrow (2, 1) \rightarrow (2, 3) \rightarrow (2, 4) \rightarrow (1, 4)$ .
In the fourth example, the hallway is already clean. Maybe you have launched the robot earlier?
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted