A11454 | Packmen Strike Back
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Game field is represented by a line of $n$ square cells. In some cells there are packmen, in some cells there are asterisks and the rest of the cells are empty. Packmen eat asterisks.
Before the game starts you can choose a movement direction, left or right, for each packman. Once the game begins all the packmen simultaneously start moving according their directions. A packman can't change the given direction.
Once a packman enters a cell containing an asterisk, packman immediately eats the asterisk. Once the packman leaves the cell it becomes empty. Each packman moves at speed 1 cell per second. If a packman enters a border cell, the packman stops. Packmen do not interfere with the movement of other packmen; in one cell there can be any number of packmen moving in any directions.
Your task is to assign a direction to each packman so that they eat the maximal number of asterisks. If there are multiple ways to assign directions to eat the maximal number of asterisks, you should choose the way which minimizes the time to do that.
Before the game starts you can choose a movement direction, left or right, for each packman. Once the game begins all the packmen simultaneously start moving according their directions. A packman can't change the given direction.
Once a packman enters a cell containing an asterisk, packman immediately eats the asterisk. Once the packman leaves the cell it becomes empty. Each packman moves at speed 1 cell per second. If a packman enters a border cell, the packman stops. Packmen do not interfere with the movement of other packmen; in one cell there can be any number of packmen moving in any directions.
Your task is to assign a direction to each packman so that they eat the maximal number of asterisks. If there are multiple ways to assign directions to eat the maximal number of asterisks, you should choose the way which minimizes the time to do that.
输入格式
The first line contains integer number $n$ ( $2<=n<=1000000$ ) — the number of cells in the game field.
The second line contains $n$ characters. If the $i$ -th character is '.', the $i$ -th cell is empty. If the $i$ -th character is '\*', the $i$ -th cell contains an asterisk. If the $i$ -th character is 'P', the $i$ -th cell contains a packman.
The field contains at least one asterisk and at least one packman.
The second line contains $n$ characters. If the $i$ -th character is '.', the $i$ -th cell is empty. If the $i$ -th character is '\*', the $i$ -th cell contains an asterisk. If the $i$ -th character is 'P', the $i$ -th cell contains a packman.
The field contains at least one asterisk and at least one packman.
输出格式
Print two integer numbers — the maximal number of asterisks packmen can eat and the minimal time to do it.
输入输出样例
输入 #1
6 *.P*P*
输出 #1
3 4
输入 #2
8 *...P..*
输出 #2
1 3
In the first example the leftmost packman should move to the right, the rightmost packman should move to the left. All the asterisks will be eaten, the last asterisk will be eaten after 4 seconds.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted