아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

Knitting Patterns

시간 제한3초메모리 제한2048 MB

요약
각 색의 등장 위치를 여러 구간으로 나누어 덮을 때, 실 사용 비용과 놓친 자리 비용, 구간 시작·종료 비용의 합을 최소로 만든다.
난이도

보통10점 중 6점

유형
동적 계획법, 문자열
정답자
아직 제출이 없습니다

문제

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⋅4=164 \cdot 4 = 16 cost), and it is used in ten stitches (10⋅2=2010 \cdot 2 = 20 cost), giving a total cost of 3636. The green and blue wool have the same cost: start once (44 cost), use for five stitches (5⋅2=105 \cdot 2 = 10 cost), strand along the back for four stitches (4⋅1=44 \cdot 1 = 4 cost), and stop using the colour (44 cost), giving a total cost of 2222.

입력

The input consists of:

  • One line with three integers aa, bb, and cc (1≤a<b<c≤10001\leq a < b < c\leq 1000), the cost of letting the wool strand through the back unused, the cost of using the wool in a stitch, and the cost of starting or ending the use of a colour of wool.
  • One line with a string ww (1≤∣w∣≤261 \leq |w| \leq 26), representing the unique letters used for denoting stitch colours.
  • One line with a string pp (1≤∣p∣≤1061 \leq |p| \leq 10^6), representing the stitch colours of the knitting pattern.

All stitch colours use English lowercase letters (a-z).

출력

Output, for every colour of wool, in the order as they are in ww, the amount of wool used in this pattern.

예제2

  1. 예제 1

    입력
    1 2 4
    rgb
    rrrrrgbgbgbgbgbrrrrr
    
    예상 출력
    36
    22
    22
    
  2. 예제 2

    입력
    2 4 1000
    ab
    abbbbbbbba
    
    예상 출력
    2024
    2032