QOJ.ac

QOJ

時間限制: 5 s 記憶體限制: 1024 MB 總分: 100

#5589. 万物皆为钉

统计

作为 Iffy Colossal Pinnacle Construction (ICPC) 公司的一名员工,你正在高空建造一座非常高的摩天大楼,你需要按特定顺序完成一系列任务。你可以随时选择跳过某项任务,但你担心跳过次数过多可能会导致建筑发生灾难性的故障。一旦任务被跳过,你就不能再回头完成它。

每项任务要么是钉子(nail),要么是螺丝(screw),要么是螺栓(bolt)。你有三种工具:锤子(用于钉子)、螺丝刀(用于螺丝)和扳手(用于螺栓)。当你开始一项新任务时,你可以选择通过丢弃当前工具来更换工具(希望当时下面没有人),但一旦这样做,你就会永久失去被丢弃的工具。

给定按顺序排列的任务列表,确定最多可以完成的任务数量。你可以选择任何工具作为初始工具。

输入格式

第一行包含一个整数 $n$ ($1 \le n \le 3 \times 10^5$),表示你需要完成的任务数量。 接下来的 $n$ 行,每行包含一个整数 $t$ ($0 \le t \le 2$)。这些是按顺序排列的任务。每项任务用 $0$(钉子)、$1$(螺丝)或 $2$(螺栓)表示。

输出格式

输出一个整数,表示最多可以完成的任务数量。

样例

样例输入 1

10
1
1
1
0
0
0
0
2
2
2

样例输出 1

10

样例输入 2

10
0
1
2
0
1
2
0
1
2
0

样例输出 2

5

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.