A13672 | Bouncing Ball
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
You're creating a game level for some mobile game. The level should contain some number of cells aligned in a row from left to right and numbered with consecutive integers starting from $1$ , and in each cell you can either put a platform or leave it empty.
In order to pass a level, a player must throw a ball from the left so that it first lands on a platform in the cell $p$ , then bounces off it, then bounces off a platform in the cell $(p + k)$ , then a platform in the cell $(p + 2k)$ , and so on every $k$ -th platform until it goes farther than the last cell. If any of these cells has no platform, you can't pass the level with these $p$ and $k$ .
You already have some level pattern $a_1$ , $a_2$ , $a_3$ , ..., $a_n$ , where $a_i = 0$ means there is no platform in the cell $i$ , and $a_i = 1$ means there is one. You want to modify it so that the level can be passed with given $p$ and $k$ . In $x$ seconds you can add a platform in some empty cell. In $y$ seconds you can remove the first cell completely, reducing the number of cells by one, and renumerating the other cells keeping their order. You can't do any other operation. You can not reduce the number of cells to less than $p$ .
Illustration for the third example test case. Crosses mark deleted cells. Blue platform is the newly added.What is the minimum number of seconds you need to make this level passable with given $p$ and $k$ ?
In order to pass a level, a player must throw a ball from the left so that it first lands on a platform in the cell $p$ , then bounces off it, then bounces off a platform in the cell $(p + k)$ , then a platform in the cell $(p + 2k)$ , and so on every $k$ -th platform until it goes farther than the last cell. If any of these cells has no platform, you can't pass the level with these $p$ and $k$ .
You already have some level pattern $a_1$ , $a_2$ , $a_3$ , ..., $a_n$ , where $a_i = 0$ means there is no platform in the cell $i$ , and $a_i = 1$ means there is one. You want to modify it so that the level can be passed with given $p$ and $k$ . In $x$ seconds you can add a platform in some empty cell. In $y$ seconds you can remove the first cell completely, reducing the number of cells by one, and renumerating the other cells keeping their order. You can't do any other operation. You can not reduce the number of cells to less than $p$ .
Illustration for the third example test case. Crosses mark deleted cells. Blue platform is the newly added.What is the minimum number of seconds you need to make this level passable with given $p$ and $k$ ?
输入格式
The first line contains the number of test cases $t$ ( $1 \le t \le 100$ ). Description of test cases follows.
The first line of each test case contains three integers $n$ , $p$ , and $k$ ( $1 \le p \le n \le 10^5$ , $1 \le k \le n$ ) — the number of cells you have, the first cell that should contain a platform, and the period of ball bouncing required.
The second line of each test case contains a string $a_1 a_2 a_3 \ldots a_n$ ( $a_i = 0$ or $a_i = 1$ ) — the initial pattern written without spaces.
The last line of each test case contains two integers $x$ and $y$ ( $1 \le x, y \le 10^4$ ) — the time required to add a platform and to remove the first cell correspondingly.
The sum of $n$ over test cases does not exceed $10^5$ .
The first line of each test case contains three integers $n$ , $p$ , and $k$ ( $1 \le p \le n \le 10^5$ , $1 \le k \le n$ ) — the number of cells you have, the first cell that should contain a platform, and the period of ball bouncing required.
The second line of each test case contains a string $a_1 a_2 a_3 \ldots a_n$ ( $a_i = 0$ or $a_i = 1$ ) — the initial pattern written without spaces.
The last line of each test case contains two integers $x$ and $y$ ( $1 \le x, y \le 10^4$ ) — the time required to add a platform and to remove the first cell correspondingly.
The sum of $n$ over test cases does not exceed $10^5$ .
输出格式
For each test case output a single integer — the minimum number of seconds you need to modify the level accordingly.
It can be shown that it is always possible to make the level passable.
It can be shown that it is always possible to make the level passable.
输入输出样例
输入 #1
3 10 3 2 0101010101 2 2 5 4 1 00000 2 10 11 2 3 10110011000 4 3
输出 #1
2 4 10
In the first test case it's best to just remove the first cell, after that all required platforms are in their places: 0101010101. The stroked out digit is removed, the bold ones are where platforms should be located. The time required is $y = 2$ .
In the second test case it's best to add a platform to both cells $4$ and $5$ : 00000 $\to$ 00011. The time required is $x \cdot 2 = 4$ .
In the third test case it's best to to remove the first cell twice and then add a platform to the cell which was initially $10$ -th: 10110011000 $\to$ 10110011010. The time required is $y \cdot 2 + x = 10$ .
In the second test case it's best to add a platform to both cells $4$ and $5$ : 00000 $\to$ 00011. The time required is $x \cdot 2 = 4$ .
In the third test case it's best to to remove the first cell twice and then add a platform to the cell which was initially $10$ -th: 10110011000 $\to$ 10110011010. The time required is $y \cdot 2 + x = 10$ .
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted