A10363 | Grandma Laura and Apples
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Grandma Laura came to the market to sell some apples. During the day she sold all the apples she had. But grandma is old, so she forgot how many apples she had brought to the market.
She precisely remembers she had $n$ buyers and each of them bought exactly half of the apples she had at the moment of the purchase and also she gave a half of an apple to some of them as a gift (if the number of apples at the moment of purchase was odd), until she sold all the apples she had.
So each buyer took some integral positive number of apples, but maybe he didn't pay for a half of an apple (if the number of apples at the moment of the purchase was odd).
For each buyer grandma remembers if she gave a half of an apple as a gift or not. The cost of an apple is $p$ (the number $p$ is even).
Print the total money grandma should have at the end of the day to check if some buyers cheated her.
She precisely remembers she had $n$ buyers and each of them bought exactly half of the apples she had at the moment of the purchase and also she gave a half of an apple to some of them as a gift (if the number of apples at the moment of purchase was odd), until she sold all the apples she had.
So each buyer took some integral positive number of apples, but maybe he didn't pay for a half of an apple (if the number of apples at the moment of the purchase was odd).
For each buyer grandma remembers if she gave a half of an apple as a gift or not. The cost of an apple is $p$ (the number $p$ is even).
Print the total money grandma should have at the end of the day to check if some buyers cheated her.
输入格式
The first line contains two integers $n$ and $p$ ( $1<=n<=40,2<=p<=1000$ ) — the number of the buyers and the cost of one apple. It is guaranteed that the number $p$ is even.
The next $n$ lines contains the description of buyers. Each buyer is described with the string half if he simply bought half of the apples and with the string halfplus if grandma also gave him a half of an apple as a gift.
It is guaranteed that grandma has at least one apple at the start of the day and she has no apples at the end of the day.
The next $n$ lines contains the description of buyers. Each buyer is described with the string half if he simply bought half of the apples and with the string halfplus if grandma also gave him a half of an apple as a gift.
It is guaranteed that grandma has at least one apple at the start of the day and she has no apples at the end of the day.
输出格式
Print the only integer $a$ — the total money grandma should have at the end of the day.
Note that the answer can be too large, so you should use $64$ -bit integer type to store it. In C++ you can use the long long integer type and in Java you can use long integer type.
Note that the answer can be too large, so you should use $64$ -bit integer type to store it. In C++ you can use the long long integer type and in Java you can use long integer type.
输入输出样例
输入 #1
2 10 half halfplus
输出 #1
15
输入 #2
3 10 halfplus halfplus halfplus
输出 #2
55
In the first sample at the start of the day the grandma had two apples. First she sold one apple and then she sold a half of the second apple and gave a half of the second apple as a present to the second buyer.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted