CF1420E.Battle Lemmings

省选/NOI-

通过率:0%

时间限制:2.00s

内存限制:512MB

AC君温馨提醒

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

题目描述

A lighthouse keeper Peter commands an army of nn battle lemmings. He ordered his army to stand in a line and numbered the lemmings from 11 to nn from left to right. Some of the lemmings hold shields. Each lemming cannot hold more than one shield.

The more protected Peter's army is, the better. To calculate the protection of the army, he finds the number of protected pairs of lemmings, that is such pairs that both lemmings in the pair don't hold a shield, but there is a lemming with a shield between them.

Now it's time to prepare for defence and increase the protection of the army. To do this, Peter can give orders. He chooses a lemming with a shield and gives him one of the two orders:

  • give the shield to the left neighbor if it exists and doesn't have a shield;
  • give the shield to the right neighbor if it exists and doesn't have a shield.

In one second Peter can give exactly one order.

It's not clear how much time Peter has before the defence. So he decided to determine the maximal value of army protection for each kk from 00 to n(n−1)2\frac{n(n-1)}2, if he gives no more that kk orders. Help Peter to calculate it!

灯塔看守人彼得指挥着一支由 nn 只战斗旅鼠组成的军队。他命令这支军队排成一列,并从左到右将旅鼠编号为 11 至 nn。其中一些旅鼠持有盾牌,且每只旅鼠最多只能持有一面盾牌。

彼得的军队受到的保护越强越好。为了计算军队的保护程度,他统计“受保护的旅鼠对”的数量:即满足如下条件的旅鼠对——该对中的两只旅鼠均未持盾,但它们之间(即在序列中位置介于二者之间)存在至少一只持盾的旅鼠。

现在到了备战时刻,需要提升军队的保护程度。为此,彼得可以下达指令:他选择一只持盾的旅鼠,并向其下达以下两种指令之一:

  • 将盾牌交给左侧相邻的旅鼠(若该旅鼠存在且未持盾);
  • 将盾牌交给右侧相邻的旅鼠(若该旅鼠存在且未持盾)。

彼得每秒恰好能下达一条指令。

目前尚不清楚彼得在防御开始前还剩多少时间。因此,他决定:对每个 kk(从 00 到 n(n−1)2\frac{n(n-1)}{2}),计算在至多下达 kk 条指令的前提下,军队保护程度所能达到的最大值。请帮助彼得完成这一计算!

输入格式

First line contains a single integer nn (1≤n≤801 \le n \le 80), the number of lemmings in Peter's army.

Second line contains nn integers aia_i (0≤ai≤10 \le a_i \le 1). If ai=1a_i = 1, then the ii-th lemming has a shield, otherwise ai=0a_i = 0.

第一行包含一个整数 nn(1≤n≤801 \le n \le 80),表示彼得军队中旅鼠的数量。

第二行包含 nn 个整数 aia_i(0≤ai≤10 \le a_i \le 1)。若 ai=1a_i = 1,则第 ii 只旅鼠持有盾牌;否则 ai=0a_i = 0。

输出格式

Print n(n−1)2+1\frac{n(n-1)}2 + 1 numbers, the greatest possible protection after no more than 0,1,…,n(n−1)20, 1, \dots, \frac{n(n-1)}2 orders.

输出 n(n−1)2+1\frac{n(n-1)}2 + 1 个数,分别表示在最多执行 0,1,…,n(n−1)20, 1, \dots, \frac{n(n-1)}2 次操作后的最大可能防护值。

输入输出样例

  • 输入#1

    5
    1 0 0 0 1

    输出#1

    0 2 3 3 3 3 3 3 3 3 3
  • 输入#2

    12
    0 0 0 0 1 1 1 1 0 1 1 0

    输出#2

    9 12 13 14 14 14 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15

说明/提示

Consider the first example.

The protection is initially equal to zero, because for each pair of lemmings without shields there is no lemmings with shield.

In one second Peter can order the first lemming give his shield to the right neighbor. In this case, the protection is two, as there are two protected pairs of lemmings, (1,3)(1, 3) and (1,4)(1, 4).

In two seconds Peter can act in the following way. First, he orders the fifth lemming to give a shield to the left neighbor. Then, he orders the first lemming to give a shield to the right neighbor. In this case Peter has three protected pairs of lemmings — (1,3)(1, 3), (1,5)(1, 5) and (3,5)(3, 5).

You can make sure that it's impossible to give orders in such a way that the protection becomes greater than three.

考虑第一个例子。

初始时保护值为 0,因为对于每一对没有盾牌的旅鼠,都不存在持有盾牌的旅鼠。

在一秒内,Peter 可以命令第一只旅鼠将其盾牌交给右侧邻居。此时保护值为 2,因为存在两对受保护的旅鼠:(1,3)(1, 3) 和 (1,4)(1, 4)。

在两秒内,Peter 可以按如下方式行动:首先,他命令第五只旅鼠将其盾牌交给左侧邻居;然后,他命令第一只旅鼠将其盾牌交给右侧邻居。此时 Peter 拥有三对受保护的旅鼠——(1,3)(1, 3)、(1,5)(1, 5) 和 (3,5)(3, 5)。

你可以验证:不存在任何指令序列能使保护值超过 3。

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

首页