Forgetful Zenyk
Limits: 2 sec., 256 MiB
This statement was translated automatically from Ukrainian.
Forgetful Zenyk is a rich programmer. Zenyk values his huge salary and stores it in two different banks (we will not mention the names of these banks, as they did not pay us for advertising). Accordingly, Zenyk has two bank cards. The PIN code for each card contains exactly \(n\) digits, each of which is 0 or 1. To avoid forgetting the PIN codes, because storing written PIN codes is very reckless, Zenyk decided to write down a string \(x\) of digits 0 and 1, for which he performed the following operation: string \(x\) contains 1 only in the positions where the digits in his passwords differ and 0 otherwise.
Zenyk knows that if he forgets one of the PIN codes, he will be able to restore the forgotten one using the string \(x\) and the other PIN code. But alas, he forgot both PIN codes. Zenyk got incredibly upset and even cried a little. Realizing that tears will not return his wealth, he decided to iterate over all possible pairs of PIN codes that produce the string \(x\) after performing the corresponding operation. Tell Zenyk how many pairs of PIN codes he will need to check.
Input
The first line contains a single integer \(n\) and a string \(x\) — the length of the PIN codes and the result of the operation for the passwords, respectively.
Output
In a single line, output the number of pairs of PIN codes that have length \(n\) and produce the string \(x\) as a result of the operation.
Constraints
\(1 \le n = |x| \le 30\),
where \(|x|\) is the length of the string \(x\),
the string \(x\) contains only digits 0 and 1,
Problem evaluation consists of the following blocks:
1 point each — examples from the statement,
8 points — a block of tests in which \(n \le 10\),
10 points — a block of tests in which \(n \le 20\),
5 points — a block of tests in which \(n \le 30\),
Points for a block will be awarded only if you give the correct answer to all tests in the block.
Samples
| Input (stdin) | Output (stdout) |
|---|---|
| 2 10 | 4 |
| Input (stdin) | Output (stdout) |
|---|---|
| 4 0111 | 16 |
Notes
Pairs that satisfy the first example: (01, 11), (11, 01), (00, 10), (10, 00).
Submit a solution
| Element Type | Created | Who | Problem | Compiler | Result | Time (sec.) | Memory (MiB) | # | Actions |
|---|
Forgetful Zenyk - Editorial
Let’s count the number of different PIN codes. We know that each digit can be chosen in two ways, independently of the others. So the answer is the product of the numbers of options for each digit, which here is \(2^n\).
If we go over all possible pairs of PIN codes and apply the operation to them, we need to count how many times we get the string \(x\). This solution passes the examples and the first test group.
If we go over only the first PIN code, then by the statement the second one is determined uniquely. This can be done as follows: if the string \(x\) has the digit 0 at the \(i\)-th position, the second PIN code gets the same digit as the first one; if it has 1 at the \(i\)-th position, we flip the digit of the first PIN code. So we can generate all PIN codes of length \(n\), and each of them is the first PIN code in exactly one suitable pair. This solution passes the second test group.
Since each PIN code makes one suitable pair and there are \(2^n\) PIN codes, the answer is \(2^n\).
So for the full solution it is enough to print \(2^n\).
| Element Type | Created | Who | Problem | Compiler | Result | Time (sec.) | Memory (MiB) | # | Actions |
|---|