#P9927. [NFLSPC #6] 真理祭坛

[NFLSPC #6] 真理祭坛

Background

It was getting late, and the crowd of onlookers had mostly dispersed. People probably did not notice that there was still a thin figure running toward the Altar of Truth.

“Which field are you a scientist in? Why are you alone?” The risk remover tilted his head and asked little Y in front of him.

“I’m not a scientist. I’m just a high school student.”

“A student?” The risk remover was confused. “Then what do you want to ask?”

“I want to know the ultimate law of the universe.”

“Since you’re just a student, how do you think I should help you understand the laws of the universe?”

“Huh?” Little Y seemed surprised. After a moment, a bit of disappointment appeared on his face. “Shouldn’t the truth of the universe be so simple that everyone can understand it... Shouldn’t it?”

“Truth is not that simple. Leaving the universe aside, I’ll casually give you some ‘principles’ here. Can you describe them in concise language?”

Little Y raised his head, looked at the dense strings of zeros and ones displayed in the sky by holographic projection, and fell into deep thought.

Problem Description

There are nn propositional variables, denoted as P0,P1,,Pn1P_0, P_1, \cdots, P_{n - 1}. Their truth values are Boolean values: either 00 or 11.

We call a principle a function that takes nn Boolean values as input and outputs one Boolean value, i.e., a mapping {0,1}n{0,1}\{0, 1\}^n \to \{0, 1\}.

Strings that satisfy certain conditions are called Well-Formed Formulas (WFF). Each WFF corresponds to exactly one principle, called the formula’s truth table. Specifically:

  • A propositional variable PiP_i is a WFF. Its truth table always outputs the ii-th input value it receives (the indices of the nn input values are 0,1,,n10, 1, \cdots, n - 1).
  • If kk strings A1,A2,,AkA_1, A_2, \cdots, A_k (k1k \geq 1) are all WFFs, then (A1A2Ak)(A_1 \land A_2 \land \cdots \land A_k) is also a WFF. When its truth table receives an input II, its output is the minimum of the outputs of the truth tables of A1,A2,,AkA_1, A_2, \cdots, A_k on input II.
  • If kk strings A1,A2,,AkA_1, A_2, \cdots, A_k (k1k \geq 1) are all WFFs, then (A1A2Ak)(A_1 \lor A_2 \lor \cdots \lor A_k) is also a WFF. When its truth table receives an input II, its output is the maximum of the outputs of the truth tables of A1,A2,,AkA_1, A_2, \cdots, A_k on input II.
  • If AA is a WFF, then ¬A\lnot A is also a WFF. Suppose the truth table of AA outputs xx on input II, then the truth table of ¬A\lnot A outputs 1x1 - x on input II.

Define the size of a WFF as the number of \land and \lor it contains. Now, given a principle, find a WFF whose truth table equals that principle, and under this condition make the formula’s size as small as possible.

Input Format

This is an output-only problem. All testdata formula1.in to formula10.in are provided in the attached files.

The first line of the input contains an integer nn.

The second line contains a string a02n1a_{0 \sim 2^n - 1} of length 2n2^n, describing the given principle: if for any 0i<n0 \leq i < n, the ii-th input value is x2imod2\left\lfloor\frac{x}{2^i}\right\rfloor \bmod 2, then the output of the principle is axa_x.

The third line contains 1010 scoring parameters; their specific use is described in “Hint”.

Output Format

For the given 1010 input files, you need to submit your output files formula1.out to formula10.out respectively.

Each output file contains one line, representing the WFF you provide. Parentheses are written as (). Propositional variable PiP_i is written as the digit i (since n10n \leq 10, this is guaranteed to be a single character). \land is written as &, \lor is written as |, and ¬\lnot is written as !. Do not omit parentheses on your own.

2
1101
1 1 1 1 1 1 1 1 1 1

(!1|0)

Hint

For all testdata, 1n101 \leq n \leq 10.

For each test case, we score as follows:

  • If your output length is greater than 10510^5, you get 00 points.
  • If your output is not a WFF, you get 00 points.
  • If the truth table of your WFF is different from the input principle, you get 00 points.
  • If none of the above happens, let s110s_{1 \sim 10} be the scoring parameters, and let SS be the size of your formula. Your score is i=110[Ssi]\sum_{i = 1}^{10}[S \leq s_i].

Each test case has a full score of 1010 points. There are 1010 test cases, so the total is 100100 points (before multiplying by the score coefficient). It is guaranteed that a full-score solution exists.


We provide a tool to test your output.

Download the attached file checker.cpp and compile it to get an executable checker.exe (Windows) or checker (Linux). Its usage is as follows:

  • Enter checker.exe X (Windows) or ./checker X (Linux) in the terminal, or run it directly and then input X followed by a newline, to test the XX-th test case formulaX.in/out.
  • Enter checker.exe A B (Windows) or ./checker A B (Linux) in the terminal, or run it directly and then input A B followed by a newline, to test with input filename AA and output filename BB.
  • If the input is invalid or the output has errors, there will be corresponding messages.
  • If there are no errors, it will output the size of your WFF.
  • The input file may match the input format description exactly, or omit the line of scoring parameters. If the checker detects that the line of scoring parameters exists, it will also output your score.

Source: NFLSPC #6 C by chenxia25.

Translated by ChatGPT 5