CF1739E.Cleaning Robot

提高+/省选-

通过率:0%

时间限制:3.00s

内存限制:512MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Consider a hallway, which can be represented as the matrix with 22 rows and nn columns. Let's denote the cell on the intersection of the ii-th row and the jj-th column as (i,j)(i, j). The distance between the cells (i1,j1)(i_1, j_1) and (i2,j2)(i_2, j_2) is ∣i1−i2∣+∣j1−j2∣|i_1 - i_2| + |j_1 - j_2|.

There is a cleaning robot in the cell (1,1)(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.

考虑一条走廊,它可以表示为一个 22 行 nn 列的矩阵。我们用 (i,j)(i, j) 表示第 ii 行与第 jj 列相交的格子。格子 (i1,j1)(i_1, j_1) 与 (i2,j2)(i_2, j_2) 之间的距离定义为 ∣i1−i2∣+∣j1−j2∣|i_1 - i_2| + |j_1 - j_2|。

清洁机器人初始位于格子 (1,1)(1, 1)。走廊中部分格子已清洁,其余格子为脏(含机器人的起始格子 (1,1)(1, 1) 本身也为清洁状态)。你的目标是清洁整条走廊,因此你将启动该机器人来完成此项任务。

机器人启动后按如下方式工作:只要至少存在一个脏格子,机器人就会在所有脏格子中选择距离其当前所在格子最近的一个,移动至该格子并将其清洁(此后该格子不再为脏)。清洁完毕后,机器人再次以其当前位置为基准,寻找最近的脏格子,依此类推。该过程持续进行,直至整条走廊全部清洁完毕。

然而,机器人程序中存在一个严重缺陷:若在某一时刻,存在多个与机器人当前位置距离相等(即均为最近)的脏格子,则机器人将发生故障。

你希望以一种不会导致机器人故障的方式清洁走廊。在启动机器人之前,你可以手动清洁若干个(可能为零个)脏格子。但你不希望亲自动手清洁太多——毕竟你拥有这个先进、智能(尽管有缺陷)的机器人来代劳。注意:你不能将已清洁的格子重新弄脏。

请计算:在保证机器人不发生故障的前提下,你最多可以保留多少个脏格子(即在启动机器人前,最少需手动清洁多少个脏格子)?

输入格式

The first line contains one integer nn (2≤n≤2⋅1052 \le n \le 2 \cdot 10^5) — the number of columns in the hallway.

Then two lines follow, denoting the 11-st and the 22-nd row of the hallway. These lines contain nn characters each, where 0 denotes a clean cell and 1 denotes a dirty cell. The starting cell of the robot (1,1)(1, 1) is clean.

第一行包含一个整数 nn(2≤n≤2⋅1052 \le n \le 2 \cdot 10^5)—— 表示走廊中的列数。

接下来是两行,分别表示走廊的第 11 行和第 22 行。每行包含 nn 个字符,其中 0 表示干净的格子,1 表示脏的格子。机器人起始位置 (1,1)(1, 1) 是干净的。

输出格式

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)(1, 2), so the path of the robot is (1,1)→(2,1)→(2,2)(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)→(1,2)→(2,2)(1, 1) \rightarrow (1, 2) \rightarrow (2, 2).

In the third example, you can clean the cell (1,2)(1, 2), so the path of the robot is (1,1)→(2,1)→(2,3)→(2,4)→(1,4)(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?

在第一个例子中,你可以清理单元格 (1,2)(1, 2),因此机器人的路径为 (1,1)→(2,1)→(2,2)(1, 1) \rightarrow (2, 1) \rightarrow (2, 2)。

在第二个例子中,你可以保持走廊原样不变,因此机器人的路径为 (1,1)→(1,2)→(2,2)(1, 1) \rightarrow (1, 2) \rightarrow (2, 2)。

在第三个例子中,你可以清理单元格 (1,2)(1, 2),因此机器人的路径为 (1,1)→(2,1)→(2,3)→(2,4)→(1,4)(1, 1) \rightarrow (2, 1) \rightarrow (2, 3) \rightarrow (2, 4) \rightarrow (1, 4)。

在第四个例子中,走廊已经清洁完毕。也许你之前就已经启动过机器人?

输入解题思路,AI测评打分。不知道怎么写?

首页