- محدودیت زمان: ۲ ثانیه
- محدودیت حافظه: ۵۱۲ مگابایت
A new form of life is recently discovered on Mars. Every alien has a DNA, that is a string with an alphabet of only two, rather than four, letters. Hence we can show the DNA of a Mars alien by a binary string. Let s be an alien DNA of length . There are regions in the DNA specified as genes. A gene located at is a substring of the DNA, containing characters from position a to position , inclusive (). A gene might overlap with or be inside the other genes.
During the life of a Mars alien, each gene is copied billions of times: a protein binds to the start of the gene, and copies the gene from start to the end. But this process is not error-free, and might produce mutations. In each mutation, a 0
in the gene is copied as 1, or vice-versa. A mutated copy does not match the gene, but might match a (possibly overlapping) substring in another position of the DNA. For instance, assume that and a gene is located at . Hence, the gene string is . A copy of this gene can be , which is mutated at the second letter. Although does not match the original substring in the DNA, it matches . A mutated copy of a gene is called degenerate if it does not appear in any place of the whole DNA. Hence, , a copy of the same gene having one mutation at the fourth letter, is degenerate, but is not.
Your task is to find, for each gene, the minimum number of mutations that can result in a degenerate copy of that gene
ورودی
There are multiple test cases in the input. The first line of each test case contains two integers and ( and ). The next line contains a binary string of length . Each of the next lines contains the location of a gene, in the form of two space-separated integers and (). The input terminates with a line
containing 0 0
that should not be processed.
خروجی
For each gene, print the minimum number of mutations that can result in a degenerate copy. If no set of mutations applied on a gene can result in a degenerate copy, print Impossible
instead.
مثال
ورودی نمونه ۱
خروجی نمونه ۱
ارسال پاسخ برای این سؤال