P15393 Unstable Metal Ingot / powerbreak
Background
**This is an interactive problem.** Due to Luogu's restrictions, the languages you may submit in include: C++11, C++14, C++17, C++20, C++23, and C++14 (GCC 9). When submitting, do not write `#include "powerbreak.h"`; instead, add the following content before your code:
```cpp
#ifndef POWERBREAK_H
#define POWERBREAK_H
class S {
private:
void* ptr; // a pointer to T, but the contestant does not know the concrete type of T
public:
S(); // default constructor
S(const S& other); // copy constructor
S(S&& other) noexcept; // move constructor
S& operator=(const S& other); // copy assignment operator
S& operator=(S&& other) noexcept; // move assignment operator
~S(); // destructor
friend S operator+(const S& x, const S& y);
friend S operator-(const S& x);
friend bool operator==(const S& x, const S& y);
};
extern const S emptyinfo;
bool isempty(const S& x);
S solve(int n, S* f, int p);
#endif
```
---
 $\gets$ This is the "unstable metal ingot".
### FWT Transform
For an array $F$ of length $2^n$ indexed from zero, define $FWT(F)$ as the array of length $2^n$ whose $S$-th entry ($0\leq S
Description
Long, long ago, you discovered a set $S$ under the lava of a volcano. This set has some magical properties, just like the legendary unstable metal ingot:
- $S$ is an abelian group.
- For $x\in S$, $1x=x, (-1)x=-x, 0x=\boldsymbol{0}$.
- For $x\in S$ with $x\neq \boldsymbol{0}$, there is no non-negative integer $k$ such that $\underbrace{x+x+\cdots+x}_{2^k\text{ copies of }x}=\boldsymbol{0}$.
Yesterday, you read in an ancient book that there once was a sequence $F\in S^{2^n}$ that contained infinite power. Because it was too dangerous, a master applied the FWT transform to seal it into $FWT(F)$ and sank it into the sea. You decided to go find this $F$ full of infinite power. Today, you finally found $FWT(F)$ and now want to study it: you want to know the largest $0\leq i\leq p$ such that $F_i\neq \boldsymbol{0}$, where $p$ is a non-negative integer $
Input Format
This is the input format of the sample interactor.
The first line contains two integers $n, p$ ($0\leq n\leq 17$, $0\leq p
Output Format
This is the output format of the sample interactor.
```plain
${return value of solve}
add_count: ${total number of addition operator calls}
constructor_count: ${total number of default constructor calls}
copy_constructor_count: ${total number of copy constructor calls}
move_constructor_count: ${total number of move constructor calls}
copy_assignment_count: ${total number of copy assignment operator calls}
move_assignment_count: ${total number of move assignment operator calls}
negate_count: ${total number of additive inverse calls}
compare_count: ${total number of equality comparison calls}
isempty_count: ${total number of isempty calls}
C1: ${C1}
C2: ${C2}
Score: ${score when the answer is correct} / ${total score}
```
Here lines 2 through 10 are output to `stderr`, and the remaining lines are output to `stdout`.
The answer file of the sample only contains the first line, i.e. the "return value of `solve`".
Explanation/Hint
### Constraints
**This problem uses bundled testing** (the minimum score is taken).
For all test data, it is guaranteed that: $0\leq n\leq 17$.
| Test point | Special property | Score |
| ---------- | ---------- | ---- |
| $1$ | $p=2^n-1$ | $40$ |
| $2$ | No special constraint | $60$ |
### Scoring Method
The final judging **will only** collect `powerbreak.cpp`; modifying other files in the contestant's directory has no effect on the judging result. **Note:**
- **An uninitialized variable of type `S` is not guaranteed to be `emptyinfo`.**
- **Do not attempt to access or modify the member variables of type `S`, otherwise it will be regarded as attacking the interactor.**
- **You may only access variables you define yourself and the `S` variables returned by the interactor; attempting to access other memory may cause a compilation error or a runtime error.**
**This problem is first subject to the same restrictions as traditional problems**, for example a compilation error will cause the whole problem to score 0 points, and a runtime error, time limit exceeded, memory limit exceeded, etc. will cause the corresponding test point to score 0 points.
For certain reasons, the total number of calls (denoted as $C_2$) to the following functions must not exceed $5\times 10^7$, otherwise unexpected errors may occur (such as wrong answer, runtime error, memory limit exceeded, etc.).
- `S();`.
- `S(const S& other);`.
- `S& operator=(const S& other);`.
- `S operator+(const S& x, const S& y);`.
- `S operator-(const S& x);`.
- `bool operator==(const S& x, const S& y)`.
- `bool isempty(const S& x)`.
Hint: the functions that are not subject to call restrictions are: `S& operator=(S&& other) noexcept;`, `S(S&& other) noexcept;`, `~S();`.
Apart from the above conditions, within a single test point, if the program performs an illegal function call or gives a wrong answer in a query operation, that test point will score 0 points. If $C_2 > 5\times 10^7$, the test point will score 0 points. Otherwise, let $C_1$ denote the number of times you use addition (`S operator+(const S& x, const S& y)`), and let $T$ be the total score of the test point, then your program receives the score $\frac{T}{\max(0, (\log_2 C_1)-n-2)+1}$, rounded down.
### Hint
We provide a `Makefile` to help contestants compile. Put `Makefile`, `grader.cpp`, `powerbreak.cpp`, and `powerbreak.h` in the same folder, and run `make powerbreak` in the terminal to obtain the executable `powerbreak`. You may also run `./compile.sh` to achieve the same effect.
### How to Use the Sample Interactor
You may have noticed that the interactor for this problem is very hard to implement, so to make it easier for contestants to understand, both the sample interactor and the distributed `powerbreak.h` will differ from those used in the official judging.
The sample interactor assumes $S=\mathbb Z/998244353\mathbb Z$, i.e. the residue system modulo $998244353$.
See above for the compilation method of the sample interactor. At runtime, the sample interactor reads from standard input data in the format of [Input Format]. The sample interactor calls `solve(n, f, p)` with this data as arguments, and outputs data in the format of [Output Format].
Note that since the interactor does not know the real answer, **the score output by the interactor is the score assuming your answer is correct; you must determine the correctness of your answer yourself**. The total score used when computing the score is $40$ when $p=2^n-1$, and $60$ otherwise.
The sample interactor contains Chinese, and its encoding is UTF-8; if you find garbled text in the sample interactor, please try switching to the correct encoding or deleting the corresponding text.
### Sample Explanation #1
This sample satisfies $n=3, p=2^n-1$. The following is the $F$ array:
```plain
659282369 496864401 920327616 0 0 861691275 44411580 0
```
You find $i=6, F_i=44411580$, so the `solve` function should return:
$$
44411580\times 2^n\equiv 355292640\pmod {998244353}
$$
If the first line of the sample interactor's output is `355292640`, it means your program outputs the correct answer and the score is the one output by the interactor; otherwise it means your program outputs a wrong answer and the score is $0$.
Besides this sample, there are five more in the attachment.
Translated by QwenWork