QOJ.ac

QOJ

总分: 100 不可用

#11678. 盒子

统计

桌子上排成一排有 $n$ 个盒子。其中,有两个相邻的盒子是空的。其余盒子中包含 $n/2 - 1$ 个红球和 $n/2 - 1$ 个绿球。每个盒子中最多有一个球。

Bajtazar 发明了一个非常有趣的游戏,目标是通过在盒子之间移动球,使得最终所有的红球都排在所有的绿球之前。在每一次移动中,你可以将两个相邻的球移动到空的盒子里,但在操作过程中不得改变它们的相对顺序。Bajtazar 请你帮忙编写一个程序来玩这个游戏。

第一行包含一个偶数 $n$($8 \le n \le 200\,000$),表示桌上盒子的数量。盒子从 0 开始编号,从左到右排列。下一行包含一个长度为 $n$ 的字符串,由数字 0、1 和 2 组成。字符串中的字符依次对应盒子 0, 1, 2, ...。数字 0 表示盒子里有红球,1 表示盒子里有绿球,2 表示盒子是空的。

样例

输入格式 1

10
0110220101

输出格式 1

5
1
3
5
8
2

或者逐个上传:

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.