A13841 | Battle Lemmings
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
A lighthouse keeper Peter commands an army of $n$ battle lemmings. He ordered his army to stand in a line and numbered the lemmings from $1$ to $n$ 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 $k$ from $0$ to $\frac{n(n-1)}2$ , if he gives no more that $k$ orders. Help Peter to calculate it!
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 $k$ from $0$ to $\frac{n(n-1)}2$ , if he gives no more that $k$ orders. Help Peter to calculate it!
输入格式
First line contains a single integer $n$ ( $1 \le n \le 80$ ), the number of lemmings in Peter's army.
Second line contains $n$ integers $a_i$ ( $0 \le a_i \le 1$ ). If $a_i = 1$ , then the $i$ -th lemming has a shield, otherwise $a_i = 0$ .
Second line contains $n$ integers $a_i$ ( $0 \le a_i \le 1$ ). If $a_i = 1$ , then the $i$ -th lemming has a shield, otherwise $a_i = 0$ .
输出格式
Print $\frac{n(n-1)}2 + 1$ numbers, the greatest possible protection after no more than $0, 1, \dots, \frac{n(n-1)}2$ orders.
输入输出样例
输入 #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)$ and $(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, 5)$ and $(3, 5)$ .
You can make sure that it's impossible to give orders in such a way that the protection becomes greater than three.
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)$ and $(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, 5)$ and $(3, 5)$ .
You can make sure that it's impossible to give orders in such a way that the protection becomes greater than three.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted