RiseOJ는 solved.ac와 제휴 관계가 없습니다. 티어 아이콘 © solved.ac. solved.ac
포럼
USACO0395 파일 입출력

Moortal Cowmbat

Platinum III 플래티넘 III
난이도
2s
시간 제한
256MB
메모리 제한
0
맞았습니다!!
0
제출 수
0.0%
정답률
레이팅

의견: 0

설명

Bessie has been playing the popular fighting game Moortal Cowmbat for a long
time now. However, the game developers have recently rolled out an update that
is forcing Bessie to change her play style.

The game uses \(M\) buttons labeled by the first \(M\) lowercase letters
(\(1 \leq M \leq 26\)). Bessie's favorite combo of moves in the game is a
length-\(N\) string \(S\) of button presses (\(1 \leq N \leq 10^5\)). However, due to
the most recent update, every combo must now be made from a series of "streaks",
where a streak is defined as a series of the same button pressed at least \(K\)
times in a row (\(1 \leq K \leq N\)). Bessie wants to modify her favorite combo to
produce a new combo of the same length \(N\), but made from streaks of button
presses to satisfy the change in rules.

It takes \(a_{ij}\) days for Bessie to train herself to press button \(j\) instead
of button \(i\) at any specific location in her combo (i.e. it costs \(a_{ij}\) to
change a single specific letter in \(S\) from \(i\) to \(j\)). Note that it might
take less time to switch from using button \(i\) to an intermediate button \(k\) and
then from button \(k\) to button \(j\) rather than from \(i\) to \(j\) directly (or
more generally, there may be a path of changes starting with \(i\) and ending with
\(j\) that gives the best overall cost for switching from button \(i\) ultimately to
button \(j\)).

Help Bessie determine the smallest possible number of days she needs to create a
combo that supports the new requirements.

Problem credits: Eric Wei

제약

SCORING

  • Test cases 2-4 satisfy \(N\le 1000, K\le 50.\)
  • Test cases 5-8 satisfy \(N\le 30,000, K\le 50.\)

Problem credits: Eric Wei

입력 형식

The first line of input contains \(N\), \(M\), and \(K\). The second line contains
\(S\), and the final \(M\) lines contain an \(M\times M\) matrix of values \(a_{ij}\),
where \(a_{ij}\) is an integer in the range \(0 \ldots 1000\) and \(a_{ii} = 0\) for
all \(i\).

출력 형식

Output a single number, representing the minimum number of days Bessie needs to
change her combo into one that satisfies the new requirements.

파일 입력 / 출력
이 문제는 표준 입출력을 사용하지 않습니다. 프로그램은 다음 파일을 읽고 써야 합니다:
입력을 읽을 파일 cowmbat.in
출력을 쓸 파일 cowmbat.out
예제 1
입력
5 5 2
abcde
0 1 4 4 4
2 0 4 4 4
6 5 0 3 2
5 5 5 0 4
3 7 0 5 0
출력
5
설명

The optimal solution in this example is to change the a into b, change the d into e, and then
change both e’s into c’s. This will take \(1+4+0+0=5\) days, and the final
combo string will be bbccc.

문제 정보

riseoj 작성

출처 올림피아드 > USACO > 2019-2020 > December > Gold

태그

평가 및 의견

Moortal Cowmbat

개요
출제자 난이도 Platinum III 플래티넘 III 의견 0 / 50 공개 집계 (커뮤니티 난이도, 주요 주제, 품질)는 의견이 충분히 모이면 공개됩니다.

Log in to rate problems.

개별 의견

아직 의견이 없습니다. 자격이 된다면 위 양식에서 가장 먼저 평가해 보세요.

풀이 제출

Moortal Cowmbat

게스트로 둘러보고 있습니다. 로그인하면 풀이를 제출하고 진행 상황을 확인할 수 있습니다. 로그인하고 제출하기
공개
C++20 Tab 들여쓰기 · Ctrl+/ 주석 토글 · Enter 자동 들여쓰기
1 1 1 0 공백: 4 · UTF-8