codeforces-scrape

Codeforces scraped problems and editorials
git clone git://git.laack.co/codeforces-scrape.git
Log | Files | Refs | README

1151A.md (2267B)


      1 Source: https://codeforces.com/problemset/problem/1151/A
      2 
      3 A. Maxim and Biology
      4 
      5 time limit per test
      6 
      7 1 second
      8 
      9 memory limit per test
     10 
     11 256 megabytes
     12 
     13 input
     14 
     15 standard input
     16 
     17 output
     18 
     19 standard output
     20 
     21 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".
     22 
     23 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".
     24 
     25 Help Maxim solve the problem that the teacher gave him.
     26 
     27 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.
     28 
     29 Input
     30 
     31 The first line contains a single integer $n$ ($4 \leq n \leq 50$) — the length of the string $s$.
     32 
     33 The second line contains the string $s$, consisting of exactly $n$ uppercase letters of the Latin alphabet.
     34 
     35 Output
     36 
     37 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.
     38 
     39 Examples
     40 
     41 Input
     42 
     43 ```
     44 4
     45 ZCTH
     46 ```
     47 
     48 Output
     49 
     50 ```
     51 2
     52 ```
     53 
     54 Input
     55 
     56 ```
     57 5
     58 ZDATG
     59 ```
     60 
     61 Output
     62 
     63 ```
     64 5
     65 ```
     66 
     67 Input
     68 
     69 ```
     70 6
     71 AFBAKC
     72 ```
     73 
     74 Output
     75 
     76 ```
     77 16
     78 ```
     79 
     80 Note
     81 
     82 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.
     83 
     84 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.