Logo
(追記) (追記ここまで)

23398번 - Listing Passwords 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
3 초 1024 MB289981.818%

문제

Michael is the manager of a barely known office and inside his room there is a locker with the money to pay the employees. Unfortunately, Michael forgot the password of the locker and it is now Dwight’s responsibility to help his boss.

The password is a sequence of N digits, containing only zeroes and ones, and Michael remembers the value at some positions of the sequence, but not the whole password. Michael also remembers M intervals of the password that are palindromes – his mind memorizes palindromes, for some reason.

An interval is a palindrome if, and only if, the first and last digits of the interval are equal, the second and second to last digits are equal, and so on.

Now Dwight wants to know how hard it will be to recover the whole password. You can help Dwight by calculating the number of possible passwords that follow what Michael remembers.

Since the answer may be very large, output it modulo 109 + 7.

입력

The first line contains the two integers N and M (1 ≤ N ≤ 3×105, 1 ≤ M ≤ 3×105), representing how many digits the password has and the number of intervals Michael remembers as palindromes, respectively.

The second line contains N characters si, representing what digit Michael remembers about each position of the password. If si is ‘0’ or ‘1’, then the i-th digit of the password is 0 or 1, respectively. If si is ‘?’, then Michael doesn’t remember the i-th digit.

Each of the next M lines contains two integers li and ri (1 ≤ li ≤ ri ≤ N), which means that the interval of the password from the digit at position li to the digit at position ri, inclusive, is a palindrome.

출력

Output the number of possible passwords that form a valid password modulo 109 + 7. Since some of Michael’s memories may be conflicting, in case there are no passwords that follow all his memories, print ‘0’.

제한

예제 입력 1

5 2
1??0?
1 3
2 4

예제 출력 1

2

예제 입력 2

3 2
???
1 1
1 3

예제 출력 2

4

예제 입력 3

5 2
1???0
1 3
3 5

예제 출력 3

0

힌트

출처

ICPC > Regionals > Latin America > Sub-Regional Brasil do ACM ICPC > Maratona de Programação SBC 2021 L번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /