Logo
(追記) (追記ここまで)

22931번 - The Paladin 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 2048 MB (추가 메모리 없음)64424271.186%

문제

A Paladin, a warrior adept at holy magic, needs your help forming spells. Being a Paladin, every spell must also be a Palindrome, meaning that it is the same string when read forwards and backwards. The cost of constructing a new spell is based on rune pair costs (costs of adjacent letters) that occur in the final spell. Rune pairs not presented in the input are not allowed in the final spell.

The total cost of a spell is the sum of all rune pair costs in the spell for each time the pair occurs in the spell. For example, if the spell is abacaba, then the cost is the sum of the costs of ab + ba + ac + ca + ab + ba.

Determine the smallest cost to make a new Paladin spell of exactly a given length.

입력

The first line of input contains two integers $n$ (1ドル \le n \le 676$) and $k$ (2ドル \le k \le 100$), where $n$ is the number of rune pairs and $k$ is the desired spell length in runes (i.e., letters).

Each of the next $n$ lines contains a string $s$ ($s$ consists of exactly two lower-case letters, which may be the same or different) and an integer $c$ (1ドル \le c \le 100$), where the string $s$ is a rune pair, and $c$ is the cost of that rune pair. All rune pairs are distinct.

출력

Output a single integer, which is the smallest possible cost for constructing a spell of length $k$ from the given runes, or $-1$ if it isn't possible.

제한

예제 입력 1

5 9
ab 4
ba 1
bd 3
db 100
bc 4

예제 출력 1

20

힌트

출처

ICPC > Regionals > North America > North America Championship > North America Championship 2021 J번

Camp > Petrozavodsk Programming Camp > Summer 2021 > Day 2: The American Contest J번

  • 문제를 만든 사람: Matt Fontaine
(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /