Mature Restaurateur

查看题解 查看答案
题目描述
Time Limit: 2000 ms
Memory Limit: 256 mb

You are already an experienced restaurateur.But you still don't have the money to hire anyone else, and you still only know how to cook ten dishes, and it's still the same ten dishes. As before, each dish requires only three ingredients, any combination of a, b and c , a, b and c are three ingredients.

Here are the ingredients and names of each dish:

1. Ingredients required: aaa, dish name: A.

2. Ingredients required: aab, dish name: B.

3. Ingredients required: aac, dish name: C.

4. Ingredients required: bbb, dish name: D.

5. Ingredients required: bba, dish name: E.

6. Ingredients required: bbc, dish name: F.

7. Ingredients required: ccc, dish name: G.

8. Ingredients required: cca, dish name: H.

9. Ingredients required: ccb, dish name: I.

10. Ingredients required: abc, dish name: J.

 

You still get your ingredients on your three farms. As before, you want to make A, it needs three ingredients of a, so you need to plant a on all three fields. So you can get enough ingredients to make A at the same time. If the next dish you want to make is B, you only need to change a farm to plant b after obtaining the ingredients for A. But you can't choose any piece, you can only choose the earliest piece of farmland to plant b. This means that if you want to grow new ingredients, you should only plant it on the earliest farms. The reason above is because you find that planting on a field too often can damage the farm(It's comforting, years of experience, no money, no cooking, but your brain). As before, only after complete A, can three farms grow new food, which means that you have just enough ingredients to make B. It is known that it takes 1 minute to plant new ingredients in a farm.

Now that you have the menu for the day, and you need to cook in order of the menu, You want to know the minimum amount of time you have to spend planting.

输入输出格式
输入描述:
Multiple sets of input. Each group just one line, s, represents the menu sequence.All the letters are uppercase and within {A,B,C,D,E,F,G,H,I,J}. 1≤|s|≤1e5。
输出描述:
Output an integer indicating the minimum amount of time you need to spend planting.
输入输出样例
输入样例#:
EIGJBB
输出样例#:
复制
9
提示
The sample explain: farm planting situation (The serial number 1 indicates the ingredient grown on the earliest farmland, the serial number 2 indicates the second earliest, and the serial number 3 indicates the latest) : 1 2 3 a b b b c c c c c c a b a b a a b a The order in which ingredients are grown: abbcccaba.
编辑器外观×
主题
字号 16px
背景
登录后免费刷此题

提交代码后在此处可查看状态