CF1151A.Maxim and Biology
入门
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Today in the scientific lyceum of the Kingdom of Kremland, there was a biology lesson. The topic of the lesson was the genomes. Let's call the genome the string "ACTG".
Maxim was very boring to sit in class, so the teacher came up with a task for him: on a given string s consisting of uppercase letters and length of at least 4, you need to find the minimum number of operations that you need to apply, so that the genome appears in it as a substring. For one operation, you can replace any letter in the string s with the next or previous in the alphabet. For example, for the letter "D" the previous one will be "C", and the next — "E". In this problem, we assume that for the letter "A", the previous one will be the letter "Z", and the next one will be "B", and for the letter "Z", the previous one is the letter "Y", and the next one is the letter "A".
Help Maxim solve the problem that the teacher gave him.
A string a is a substring of a string b if a can be obtained from b by deletion of several (possibly, zero or all) characters from the beginning and several (possibly, zero or all) characters from the end.
今天,克雷姆兰王国科学中学正在上一节生物课,课程主题是基因组。我们称字符串 "ACTG" 为基因组。
马克西姆坐在教室里感到非常无聊,于是老师给他布置了一道题:给定一个由大写字母组成的字符串 s,其长度至少为 4,你需要找出使基因组 "ACTG" 作为其子串出现所需的最少操作次数。每次操作允许你将字符串 s 中的任意一个字母替换为它在字母表中的前一个或后一个字母。例如,对于字母 "D",它的前一个字母是 "C",后一个字母是 "E"。在本题中,我们认为字母 "A" 的前一个字母是 "Z",后一个字母是 "B";而字母 "Z" 的前一个字母是 "Y",后一个字母是 "A"。
请帮助马克西姆解决老师布置的这道题。
若字符串 a 可通过从字符串 b 的开头删除若干(可能为零个或全部)字符、并从结尾删除若干(可能为零个或全部)字符而得到,则称 a 是 b 的一个子串。
输入格式
The first line contains a single integer n (4≤n≤50) — the length of the string s.
The second line contains the string s, consisting of exactly n uppercase letters of the Latin alphabet.
第一行包含一个整数 n(4≤n≤50)—— 字符串 s 的长度。
第二行包含字符串 s,由恰好 n 个大写拉丁字母组成。
输出格式
Output the minimum number of operations that need to be applied to the string s so that the genome appears as a substring in it.
输出使字符串 s 中出现基因组作为子串所需的最少操作次数。
输入输出样例
输入#1
4 ZCTH
输出#1
2
输入#2
5 ZDATG
输出#2
5
输入#3
6 AFBAKC
输出#3
16
说明/提示
In the first example, you should replace the letter "Z" with "A" for one operation, the letter "H" — with the letter "G" for one operation. You will get the string "ACTG", in which the genome is present as a substring.
In the second example, we replace the letter "A" with "C" for two operations, the letter "D" — with the letter "A" for three operations. You will get the string "ZACTG", in which there is a genome.
在第一个例子中,你需要将字母“Z”替换为“A”,花费 1 次操作;将字母“H”替换为“G”,也花费 1 次操作。最终得到字符串“ACTG”,其中包含基因组作为子串。
在第二个例子中,我们将字母“A”替换为“C”,花费 2 次操作;将字母“D”替换为“A”,花费 3 次操作。最终得到字符串“ZACTG”,其中包含基因组。
输入解题思路,AI测评打分。不知道怎么写?