Listing Passwords
Time limit3sMemory limit1024 MB
Count the 0/1 strings of length N that fit the fixed digits and M required palindrome intervals, modulo 1e9+7, or 0 on conflict.
- Level
Hard8 of 10
- Topics
- Union-find, String, Math
- Solved
- No attempts yet
Problem
Michael is the manager of a barely known office, and his room has a locker that holds the money for the employees. Unfortunately, Michael forgot the locker password, so it is now Dwight's job to help his boss. The password is a sequence of digits, each either 0 or 1. Michael remembers the value at some positions but not the whole password. He also remembers intervals of the password that are palindromes. He remembers palindromes well, for some reason. An interval is a palindrome if its first and last digits are equal, its second and second-to-last digits are equal, and so on. Dwight wants to know how hard it is to recover the whole password. He can calculate the number of possible passwords that match what Michael remembers. The answer may be very large, so output it modulo .
Input
The first line contains two integers and (, ). The second line contains a string of characters . If is 0 or 1, the -th digit of the password is that value. If is ?, Michael does not remember the -th digit. Each of the next lines contains two integers and (), meaning the part of the password from position to position , inclusive, is a palindrome.
Output
If Michael's memories conflict so that no password satisfies all of them, output 0. Otherwise, output the number of passwords that satisfy all of them, modulo .