#P2114. [NOI2014] 起床困难综合症

    ID: 1072 远端评测题 1000ms 125MiB 尝试: 0 已通过: 0 难度: 6 上传者: 标签>动态规划,dp贪心2014NOI 系列位运算,按位

[NOI2014] 起床困难综合症

Description

In the 21st century, many people have developed a strange illness: the Wake-Up Difficulty Syndrome, whose clinical symptoms are: difficulty getting up and poor mental state after getting up. As a sunny and energetic teenager, atm has always fought against this syndrome. By studying relevant literature, he discovered the cause of the illness: deep under the Pacific Ocean, there is a giant dragon named drd, who masters the essence of sleep and can arbitrarily extend everyone’s sleep time. It is precisely due to drd’s activities that the Wake-Up Difficulty Syndrome has worsened and is spreading at an alarming rate around the world. To completely eliminate this disease, atm decides to go to the seabed to defeat this evil dragon. After enduring many hardships, atm finally arrives at drd’s location, ready for a tough and arduous battle. drd has a very special skill: his defensive front can use certain operations to change the damage he receives. Specifically, drd’s defensive front consists of nn defense gates. Each defense gate includes an operation op\text{op} and a parameter tt, where the operation must be one of OR,XOR,AND\texttt{OR}, \texttt{XOR}, \texttt{AND}, and the parameter must be a non-negative integer. If the attack power before passing the gate is xx, then after passing this gate it becomes xoptx\,\text{op}\,t. The final damage drd receives is the attack power obtained by applying all nn defense gates in order to the opponent’s initial attack power xx.

Because atm’s ability is limited, his initial attack power can only be an integer between 00 and mm (that is, he can choose his initial attack power from 0,1,,m0, 1, \ldots, m, but the attack power after passing through the defense gates is not limited by mm). To save energy, he wants to choose a suitable initial attack power so that his attack causes the maximum possible damage to drd. Please help him compute the maximum damage his single attack can cause.

Input Format

The first line of the input file contains 22 integers, n,mn, m, indicating that drd has nn defense gates, and atm’s initial attack power can be any integer from 00 to mm.

The next nn lines describe each defense gate in order. Each line contains a string op\text{op} and a non-negative integer tt, separated by a space, with op\text{op} first and tt second. op\text{op} denotes the operation of the defense gate, and tt denotes its parameter.

Output Format

Output a single integer on one line: the maximum damage that atm’s single attack can cause to drd.

3 10
AND 5
OR 6
XOR 7
1

Hint

【Sample Explanation】

atm can choose an initial attack power from 0,1,,100, 1, \ldots, 10.

Suppose the initial attack power is 44. The final attack power is computed as follows:

  • 4 AND 5=44 \texttt{ AND } 5 = 4;
  • 4 OR 6=64 \texttt{ OR } 6 = 6;
  • 6 XOR 7=16 \texttt{ XOR } 7 = 1.

Similarly, we can compute that when the initial attack power is 1,3,5,7,91, 3, 5, 7, 9, the final attack power is 00; when the initial attack power is 0,2,4,6,8,100, 2, 4, 6, 8, 10, the final attack power is 11. Therefore, the maximum damage atm’s single attack can cause to drd is 11.

【Constraints and Conventions】

  • Special property A\mathrm A: There exists a defense gate equal to AND 0\texttt{AND}~0.
  • Special property B\mathrm B: All defense gates use the same operation.

For all testdata, it is guaranteed that 2n1052 \le n \le 10^5, 0m1090 \le m \le 10^9, 0t1090 \le t \le 10^9, and op\mathrm{op} is one of AND,OR,XOR\verb!AND!,\verb!OR!,\verb!XOR!.

Translated by ChatGPT 5