시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
---|---|---|---|---|---|
3 초 (추가 시간 없음) | 2048 MB | 7 | 5 | 5 | 71.429% |
It is the most relaxing hobby of anyone's grandma: knitting! Your grandma uses a lot of wool, even for the most simple patterns that she is knitting. You are sure that she can be more efficient with her wool, so you decide to write a program that calculates the most efficient use of wool.
A knitting pattern is a long list of stitches, where each stitch can use a different colour. (Most real-life knitting patterns are two-dimensional, the input is one-dimensional for simplicity.) There is a cost for starting or ending the use of a certain colour, for using the wool in a stitch, and for letting it strand through the back unused. For a given knitting pattern, calculate the least possible amount of wool required for every colour of wool.
As an example, consider the first sample case. There are three colours of wool (red, green, and blue). The red wool is used at the start and at the end of the pattern: it is most efficient to start and stop using the red wool for both parts separately ($4 \cdot 4 = 16$ cost), and it is used in ten stitches ($10 \cdot 2 = 20$ cost), giving a total cost of $36$. The green and blue wool have the same cost: start once ($4$ cost), use for five stitches ($5 \cdot 2 = 10$ cost), strand along the back for four stitches ($4 \cdot 1 = 4$ cost), and stop using the colour ($4$ cost), giving a total cost of $22$.
The input consists of:
All stitch colours use English lowercase letters (a-z
).
Output, for every colour of wool, in the order as they are in $w$, the amount of wool used in this pattern.
1 2 4 rgb rrrrrgbgbgbgbgbrrrrr
36 22 22
2 4 1000 ab abbbbbbbba
2024 2032
ICPC > Regionals > Europe > Northwestern European Regional Contest > Benelux Algorithm Programming Contest > BAPC 2022 Preliminaries K번