#P8271. [USACO22OPEN] COW Operations S
[USACO22OPEN] COW Operations S
Problem Description
Bessie found a string of length at most that contains only the characters 'C', 'O', and 'W'. She wants to know whether she can use the following operations to turn the string into a single letter 'C' (her favorite letter):
-
Choose two adjacent equal letters and delete them.
-
Choose one letter and replace it with any permutation of the other two letters.
Knowing the answer for the whole string alone is not enough for Bessie, so she wants to know the answers for () substrings of .
Input Format
The first line contains .
The second line contains .
The next lines each contain two integers and (), where is the length of .
Output Format
Output a string of length . If the -th substring can be transformed, then the -th character should be 'Y', otherwise it should be 'N'.
COW
6
1 1
1 2
1 3
2 2
2 3
3 3
YNNNYN
Hint
[Sample Explanation]
The answer to the first query is "Yes", because the first character of is already equal to 'C'.
The answer to the fifth query is "Yes", because the substring formed by the second to third characters of , namely OW, can be turned into 'C' in two operations:
OW
-> CWW
-> C
All other substrings of the sample string COW cannot be transformed into 'C'.
[Test Point Properties]
- Test points 2-4 satisfy and .
- Test points 5-11 have no additional constraints.
Translated by ChatGPT 5