#P9657. [ICPC2021 Macao R] the Matching System

    ID: 9019 远端评测题 3000ms 256MiB 尝试: 0 已通过: 0 难度: 7 上传者: 标签>动态规划,dp2021Special JudgeO2优化前缀和ICPC澳门

[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 0\textbf{0} and 1\textbf{1}), and the latter string consists of four types of characters 0\textbf{0}, 1\textbf{1}, *\textbf{*}, ^, where *\textbf{*} 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:

  • *\textbf{*}: The system will enumerate ii from LL to 00, where LL 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 *\textbf{*} in the pattern string matches the consecutive ii 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 *\textbf{*} enumeration.
  • 0,1\textbf{0,1}: The system will stop and return to the previous *\textbf{*} enumeration if the to-be-matched string has been exhausted. Otherwise, it consumes 11 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 *\textbf{*} enumeration.
  • ^: The system will stop and return to the previous *\textbf{*} enumeration if the to-be-matched string has been exhausted. Otherwise, it consumes 11 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 *\textbf{*} 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 *\textbf{*} (i.e., enumerate ii from 00 to LL).

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 nn 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 nn (1n1031 \le n \le 10^3) 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 33 lines. Then output the pattern string, the to-be-matched string, and the energy cost for the minimum matching method in the next 33 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 (109+7)(10^9+7). 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