#P7803. [JOI Open 2021] 杂交 / Crossing
[JOI Open 2021] 杂交 / Crossing
Description
In your repository, there are sequences of length , consisting only of J, O, and I. You may perform a C operation (full name: Cross operation, abbreviated as C operation). In each C operation, you choose two strings from the repository. The string produced after the C operation is . For any , let the characters at position in these three strings be , respectively, then:
| J | J | |
| O | I | |
| I | O | |
| O | J | I |
| O | ||
| I | J | |
| I | J | O |
| O | J | |
| I | ||
The meaning of the table above is: when are the corresponding characters, then must be the corresponding character as well.
After performing a C operation, the produced string will be added into the repository.
You are given a string of length consisting only of J, O, and I, and integers and characters . These define strings of length by the following rule:
is obtained from by replacing the characters from the -th to the -th position with .
For each string (including ), determine whether it can be obtained from the given initial repository by performing the C operation one or more times. If the string is exactly the same as one of the strings already in the repository, it is also considered “obtainable by performing C operations”; see in Sample 1 for details.
Any strings added to the repository while processing the -th string will be cleared before determining the -th string.
Input Format
The first line contains an integer , the length of the strings.
The next lines contain , the strings in the initial repository.
The fifth line contains an integer , the number of given strings.
The sixth line contains a string , as described above.
The next lines each contain two integers and one character , as described above.
Output Format
Output lines, each being Yes or No. The -th line indicates whether can be obtained from the initial repository.
4
JOJO
JJOI
OJOO
3
IJOJ
1 4 O
2 2 J
2 4 I
Yes
No
Yes
Yes
3
JOI
JOI
JOI
2
OJI
1 2 O
1 1 J
No
No
Yes
Hint
Explanation of Sample 1
- can be obtained by performing a C operation on
JJOIandOJOO. - is
OOOO, and cannot be obtained from the repository by performing C operations. - is
OJOO. SinceOJOOis in the repository, it can be obtained. - is
OIII:- Perform a C operation on
JJOIandOJOOto produceIJOJ. - Perform a C operation on
JOJOandIJOJto produceOIII.
- Perform a C operation on
Explanation of Sample 2
- cannot be obtained from the repository by performing C operations.
- is
OOI, and cannot be obtained from the repository by performing C operations. - is
JOI. SinceJOIis in the repository, it can be obtained.
Constraints and Notes
This problem uses bundled testdata.
- Subtask 1 (3 pts): , .
- Subtask 2 (23 pts): .
- Subtask 3 (23 pts): .
- Subtask 4 (51 pts): No special constraints.
For of the testdata:
- .
- are strings of length consisting only of
J,O, andI. - .
- is a string of length consisting only of
J,O, andI. - .
J,O,I.
Note
Translated from JOI 2020 / 2021 Open Contest A Crossing.
Translated by ChatGPT 5
京公网安备 11011102002149号