Baltic Olympiad in Informatics: 2018 Day 1, Problem 2
As you are probably aware, human DNA can be represented as a long string over an alphabet of size four (A, C, G, T), where each symbol represents a distinct nucleobase (respectively; adenine, cytosine, guanine, and thymine).
For martians, however, things are a bit different; research conducted on the latest martian captured by NASA revealed that martian DNA consists of a whopping
Now, a certain research group interested in exploiting martian DNA in artificial intelligence applications has requested to get a single consecutive piece of a martian DNA string. For
You are interested in finding the shortest substring of the DNA which satisfies their requirements.
Input
The first line contains three integers
The second line contains
Each of the following
Output
Output a single integer, the length of the shortest consecutive substring of the DNA that satisfies the researchers' requirements. If no such substring exists, output impossible
.
Constraints
Your solution will be tested on a set of test groups, each worth a number of points. Each test group contains a set of test cases. To get the points for a test group you need to solve all test cases in the test group. Your final score will be the maximum score of a single submission.
Group | Points | Limits |
---|---|---|
1 | 16 | |
2 | 24 | |
3 | 28 | |
4 | 32 |
Explanation of Samples
In the first sample, there are three substrings of length 2 that contain one each of nucleobases 0 and 1 (namely 0 1
, 1 0
and 0 1
), but no substrings of length 1. Thus the shortest length is 2.
In the second sample, the (unique) optimal substring is 1 3 2 0 1 2 0
.
In the third sample, there aren't enough nucleobases of type 0.
Sample Input 1
5 2 2
0 1 1 0 1
0 1
1 1
Sample Output 1
2
Sample Input 2
13 4 3
1 1 3 2 0 1 2 0 0 0 0 3 1
0 2
2 1
1 2
Sample Output 2
7
Sample Input 3
5 3 1
1 2 0 1 2
0 2
Sample Output 3
impossible
Comments