No.3757 Happy End
レベル :
/ AI推定難易度 : 500
/ 実行時間制限 : 1ケース 2.000秒 / メモリ制限
: 1024 MB / 標準ジャッジ問題
タグ : / 解いたユーザー数 97
作問者 :
ei1333333
/ テスター :
kyoprouno
ei13333333
タグ : / 解いたユーザー数 97
作問者 :
ei1333333
/ テスター :
kyoprouno
ei13333333
問題文最終更新日: 2026-10-06 04:19:18
English (AI translation)
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence.
Back to the original
yukicoder contest 517
(順位表)
の他の問題:
Problem Statement
A string $T$ is called a good string if $T$ satisfies all of the following conditions.
- The last $5$ characters are
HAPPY. HAPPYdoes not appear as a contiguous substring anywhere other than at the end.
You are given a string $S$ of length $N$ consisting of uppercase English letters (A-Z).
You may perform the following operation any number of times: choose $1$ character of $S$ and rewrite it to a different character.
Find the minimum number of operations required to make $S$ a good string.
Constraints
- $5 \leq N \leq 3 \times 10^5$
- $N$ is an integer
- $S$ is a string of length $N$ consisting of uppercase English letters (
A-Z)
Input
$N$ $S$
Output
Output the answer on $1$ line.
Sample
Sample 1
Input
9 KAGUYABAD
Output
4
By rewriting it to KAGUHAPPY, you can make it a good string with $4$ operations.
Sample 2
Input
10 HAPPYHAPPY
Output
1
Sample 3
Input
5 HAPPY
Output
0
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。