codeforces-scrape

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

701C.md (2168B)


      1 Source: https://codeforces.com/problemset/problem/701/C
      2 
      3 C. They Are Everywhere
      4 
      5 time limit per test
      6 
      7 2 seconds
      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 Sergei B., the young coach of Pokemons, has found the big house which consists of *n* flats ordered in a row from left to right. It is possible to enter each flat from the street. It is possible to go out from each flat. Also, each flat is connected with the flat to the left and the flat to the right. Flat number 1 is only connected with the flat number 2 and the flat number *n* is only connected with the flat number *n* - 1.
     22 
     23 There is exactly one Pokemon of some type in each of these flats. Sergei B. asked residents of the house to let him enter their flats in order to catch Pokemons. After consulting the residents of the house decided to let Sergei B. enter one flat from the street, visit several flats and then go out from some flat. But they won't let him visit the same flat more than once.
     24 
     25 Sergei B. was very pleased, and now he wants to visit as few flats as possible in order to collect Pokemons of all types that appear in this house. Your task is to help him and determine this minimum number of flats he has to visit.
     26 
     27 Input
     28 
     29 The first line contains the integer *n* (1 ≤ *n* ≤ 100 000) — the number of flats in the house.
     30 
     31 The second line contains the row *s* with the length *n*, it consists of uppercase and lowercase letters of English alphabet, the *i*-th letter equals the type of Pokemon, which is in the flat number *i*.
     32 
     33 Output
     34 
     35 Print the minimum number of flats which Sergei B. should visit in order to catch Pokemons of all types which there are in the house.
     36 
     37 Examples
     38 
     39 Input
     40 
     41 ```
     42 3  
     43 AaA
     44 ```
     45 
     46 Output
     47 
     48 ```
     49 2
     50 ```
     51 
     52 Input
     53 
     54 ```
     55 7  
     56 bcAAcbc
     57 ```
     58 
     59 Output
     60 
     61 ```
     62 3
     63 ```
     64 
     65 Input
     66 
     67 ```
     68 6  
     69 aaBCCe
     70 ```
     71 
     72 Output
     73 
     74 ```
     75 5
     76 ```
     77 
     78 Note
     79 
     80 In the first test Sergei B. can begin, for example, from the flat number 1 and end in the flat number 2.
     81 
     82 In the second test Sergei B. can begin, for example, from the flat number 4 and end in the flat number 6.
     83 
     84 In the third test Sergei B. must begin from the flat number 2 and end in the flat number 6.