Copy and Paste
Time limit3sMemory limit1024 MB
Find the dictionary-order position of name A among all file names reachable from [0] within K copy and paste rounds, modulo 998244353.
- Level
Medium7 of 10
- Topics
- Combinatorics, Dynamic programming, Bit manipulation
- Solved
- No attempts yet
Problem
Mingu, who has nothing left to do, is playing a copy and paste game. The game is about looking at the file names that appear as files are copied and pasted.
A file name is a sequence of length at least 1 whose elements are integers from 0 up to but not including . One copy and paste round consists of the following steps.
- Copy step: select every file in the folder.
- Paste step: for each selected file , repeat the following. Files created during this step are not selected.
- Create a file named with 0 appended to the end. If a file with the same name already exists, do not create it.
- For every with , create a file whose name is the last element of XORed with . If a file with the same name already exists, do not create it.
- After the paste step ends, deselect all selected files.
For example, with and a folder holding only [0], repeating copy and paste changes the folder contents as follows.
- Start:
[0] - After 1 round:
[0],[0, 0],[1],[2] - After 2 rounds:
[0],[0, 0],[0, 0, 0],[0, 1],[0, 2],[1],[1, 0],[2],[2, 0],[3]
Mingu, an expert at copy and paste, gave you the following problem. Starting from a folder that holds only [0], find the position in dictionary order of the file name that Mingu gives after rounds of copy and paste.
Find the answer modulo 998 244 353 for Mingu.
Input
The first line contains integers and , separated by a space. (; )
The second line contains the length of the file name . ()
The third line contains the elements of , separated by spaces. (; )
The input is given only when a file named exists after rounds of copy and paste.
Output
Let the smallest file name in dictionary order have position 1. Print the position of in dictionary order, modulo 998 244 353.
Hint
A sequence comes before a sequence in dictionary order when there is a positive integer that satisfies all of the following.
- For every positive integer less than , both and exist and .
- exists.
- does not exist, or .