#P9657. [ICPC2021 Macao R] the Matching System
[ICPC2021 Macao R] the Matching System
题目描述
As the leader of the safety department, you are asked to check an ancient matching system in your company.
The system is fed with two strings, a to-be-matched string and a pattern string, and will determine whether the former can match the latter. The former string is a strict binary string(i.e., contains only and ), and the latter string consists of four types of characters , , , ^, where means match zero or more arbitrary binary characters, and ^ means match exactly one binary character.
The system has two matching methods: maximum matching and minimum matching.
Consider the starting positions of the two strings. The maximum matching method will make different decisions based on the current character of the pattern string:
- : The system will enumerate from to , where is the remaining length of the to-be-matched string. Before each enumeration starts, the system consumes 1 unit of energy. Then it temporarily assumes that the current in the pattern string matches the consecutive characters in the to-be-matched string, and tries to match the remaining positions of two strings recursively. As long as one attempt is successful, the system will give up the remaining enumeration and stop the whole system. Otherwise, it will try the next enumeration until all attempts are tried and finally return to the previous enumeration.
- : The system will stop and return to the previous enumeration if the to-be-matched string has been exhausted. Otherwise, it consumes unit of energy to compare the current characters between the pattern string and the to-be-matched string. It will continue analyzing the remaining positions of these two strings if the result is the same, otherwise, return back to the previous enumeration.
- ^: The system will stop and return to the previous enumeration if the to-be-matched string has been exhausted. Otherwise, it consumes unit of energy and moves on of two strings.
When the pattern string is exhausted, the system will check the to-be-matched string at the same time. It will return Yes
and stop the whole process if the to-be-matched string is also exhausted, otherwise, it will return to the previous enumeration. After all attempts are tried and no matching method is found, the system will eventually return No
.
Minimum matching does a similar thing except for the enumeration order of (i.e., enumerate from to ).
These two matching methods seem not very effective, so you want to hack them. Please construct both a pattern string and a to-be-matched string of length for each matching method, so that the system answers Yes
and the energy consumption is as large as possible.
输入格式
There is only one test case in each test file.
The first and only line contains an integer () indicating the length of strings need to be constructed.
输出格式
Please output the pattern string, the to-be-matched string, and the energy cost for the maximum matching method in the first lines. Then output the pattern string, the to-be-matched string, and the energy cost for the minimum matching method in the next lines.
If there are multiple constructing ways, you can output any of them.
The energy cost may be very large, so you need to output the value modulo . Note that this is only for your convenience and you need to maximize the energy cost before the modulus.
3
*0*
011
8
**1
101
7