AtCoder Grand Contest 061
E
Increment or XOR
AtCoder
⌀ 3901
原题
← DF →
翻译中…

Problem Statement

翻译中…

There is a non-negative integer $X$ initially equal to $S$. One can perform the following operations, in any order, any number of times:

翻译中…
  • Add $1$ to $X$. This has a cost of $A$.
  • Choose $i$ between $1$ and $N$, and replace $X$ with $X \oplus Y_i$. This has a cost of $C_i$. Here, $\oplus$ denotes bitwise $\mathrm{XOR}$.
翻译中…

Find the smallest total cost to make $X$ equal to a given non-negative integer $T$, or report that this is impossible.

翻译中…

What is bitwise $\mathrm{XOR}$? The bitwise $\mathrm{XOR}$ of non-negative integers $A$ and $B$, $A \oplus B$, is defined as follows: When $A \oplus B$ is written in base two, the digit in the $2^k$'s place ($k \geq 0$) is $1$ if exactly one of the digits in that place of $A$ and $B$ is $1$, and $0$ otherwise. For example, we have $3 \oplus 5 = 6$ (in base two: $011 \oplus 101 = 110$). Generally, the bitwise $\mathrm{XOR}$ of $k$ non-negative integers $p_1, p_2, p_3, \dots, p_k$ is defined as $(\dots ((p_1 \oplus p_2) \oplus p_3) \oplus \dots \oplus p_k)$. We can prove that this value does not depend on the order of $p_1, p_2, p_3, \dots, p_k$.

翻译中…

Constraints

翻译中…
  • $1 \leq N \leq 8$
  • $0 \leq S, T < 2^{40}$
  • $0 \leq A \leq 10^5$
  • $0 \leq Y_i < 2^{40}$ ($1 \leq i \leq N$)
  • $0 \leq C_i \leq 10^{16}$ ($1 \leq i \leq N$)
  • All values in the input are integers.
翻译中…

Input

翻译中…

Input is given from Standard Input in the following format:

翻译中…

N S T A
Y_1 C_1
\vdots
Y_N C_N

翻译中…

Output

翻译中…

If the task is impossible, print -1. Otherwise, print the smallest total cost.

翻译中…

样例

Input #1
1 15 0 1
8 2
Output #1
5
You can make $X$ equal to $T$ in the following manner: - Choose $i=1$ and replace $X$ with $X \oplus 8$ to get $X=7$. This has a cost of $2$. - Add $1$ to $X$ to get $X=8$. This has a cost of $1$. - Choose $i=1$ and replace $X$ with $X \oplus 8$ to get $X=0$. This has a cost of $2$.
Input #2
3 21 10 100
30 1
12 1
13 1
Output #2
3
Input #3
1 2 0 1
1 1
Output #3
-1
Input #4
8 352217 670575 84912
239445 2866
537211 16
21812 6904
50574 8842
380870 5047
475646 8924
188204 2273
429397 4854
Output #4
563645
题目信息
题号
agc061_e
时间限制
2 s
内存限制
1024 MB

题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。