CF632A.Grandma Laura and Apples
普及-
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
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.
奶奶劳拉来到市场卖苹果。当天她卖出了自己所带的所有苹果。但由于奶奶年纪大了,她忘记了自己最初带了多少个苹果到市场。
她清楚地记得自己共有 n 位买家,每位买家恰好买走了她当时所剩苹果数量的一半;此外,若购买时刻她所剩苹果数为奇数,则她还会额外赠送半个苹果(即总共给出“一半加半个”苹果),如此持续直至所有苹果售罄。
因此,每位买家拿走的苹果总数均为正整数,但其中半个苹果可能未付费(仅当购买时刻剩余苹果数为奇数时发生)。
对于每位买家,奶奶都记得当时是否赠送了半个苹果作为礼物。每个苹果的价格为 p(已知 p 是偶数)。
请输出奶奶当天结束时应获得的总金额,以便核对是否有买家欺骗了她。
输入格式
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.
第一行包含两个整数 n 和 p(1 ≤ n ≤ 40,2 ≤ p ≤ 1000)—— 分别表示买家数量和一个苹果的价格。保证 p 是偶数。
接下来的 n 行描述了每位买家。每位买家用字符串 half 表示他仅买走了当时剩余苹果数量的一半;用字符串 halfplus 表示奶奶额外赠送了他半个苹果(即他买走了当时剩余苹果数量的一半,再额外获得半个苹果)。
保证奶奶在当天开始时至少有一个苹果,且在当天结束时没有剩余苹果。
输出格式
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.
输出唯一的整数 a —— 奶奶一天结束时应拥有的总金额。
注意:答案可能非常大,因此你需要使用 64 位整数类型来存储它。在 C++ 中可使用 long long 整数类型,在 Java 中可使用 long 整数类型。
输入输出样例
输入#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.
在第一个样例中,奶奶在一天开始时有两个苹果。首先她卖出了一个苹果,然后她将第二个苹果的一半卖出,并将第二个苹果的另一半作为礼物送给了第二位买家。
输入解题思路,AI测评打分。不知道怎么写?