#P3825. [NOI2017] 游戏
[NOI2017] 游戏
Description
Little L plans to play games. Each game uses one map, and Little L will choose a car to complete the game on that map.
Little L has three cars, denoted by uppercase letters , , and . There are four types of maps, denoted by lowercase letters , , , and .
Among them, car is not suitable for map , car is not suitable for map , car is not suitable for map , while map is suitable for all cars.
Maps that are suitable for all cars are rare; there will be at most of them.
The maps for the games can be described by a string of lowercase letters. For example, means Little L plans to play games: the -st and -th maps are of type , suitable for all cars; the -nd and -rd maps are of type , unsuitable for car ; the -th and -th maps are of type , unsuitable for car ; and the -th and -th maps are of type , unsuitable for car .
Little L has some special requirements, which can be described by a quadruple , meaning: if the car used in game is , then the car used in game must be .
Can you help Little L choose a car for each game? If there are multiple solutions, output any of them.
If there is no solution, output -1.
Input Format
The first line contains two non-negative integers, and .
The second line contains a string .
The meanings of , , and are as described above. The string contains characters, and exactly of them are the lowercase letter .
The third line contains a positive integer , indicating that there are car-usage rules.
The next lines each contain a quadruple , where and are integers, and and are characters among , , and , with meanings as described above.
Output Format
Output one line.
If there is no solution, output -1.
If there is a solution, output a string of length consisting only of uppercase letters , , and , indicating how Little L arranges the cars for these games. If multiple solutions exist, output any one of them.
3 1
xcc
1
1 A 2 B
ABA
Hint
Sample 1 Explanation
Little plans to play games. The -st map is of type , suitable for all cars, and the -nd and -rd maps are of type , unsuitable for car .
Little requires: if car is used in game , then car must be used in game .
Assigning cars , , to the games satisfies all conditions.
Assigning cars or to the games also satisfies all conditions and is considered correct.
However, assigning cars or does not satisfy all conditions, so it is not considered correct.
Sample 2
See the attached file.
Constraints
| Test point ID | Other properties | |||
|---|---|---|---|---|
| None | ||||
| only contains | ||||
| None | ||||
| only contains or | ||||
| None | ||||
| only contains | ||||
| None | ||||
| only contains or | ||||
| None | ||||
| only contains or | ||||
| None | ||||
| only contains or | ||||
| None |
Translated by ChatGPT 5
京公网安备 11011102002149号