#P13714. 淘汰(Hard ver.)
淘汰(Hard ver.)
Description
Given two numbers and four arrays of length , you can perform the following two operations on any number of times:
-
For any (), pay a cost of to assign .
-
For any (), pay a cost of to assign .
Where and represent bitwise AND and bitwise OR operations respectively.
You need to determine the minimum cost to transform into . If it is impossible, output .
Help: What are bitwise AND and bitwise OR?
Input Format
This problem contains multiple test cases.
The first line of input contains an integer , indicating the number of test cases.
This is followed by test cases, each formatted as follows:
The first line contains four integers , where are as described in the problem statement. indicates that for this test case, , and .
The second line contains integers, representing .
The third line contains integers, representing .
The fourth line contains integers, representing .
The fifth line contains integers, representing .
Output Format
For each test case, output one integer, representing the answer.
2
4 3 1 0
1 1 0 1
0 1 0 0
20 16 13 18
18 19 3 2
1 2 0 2
1
1
9
20
13
-1
3
2 10 190 256
973 290
349 836
19 9
73 72
4 10 530 187
973 290 416 734
349 187 359 377
36 13 9 28
27 47 21 45
8 10 344 264
973 290 416 734 296 269 947 449
349 187 664 308 31 177 852 787
79 68 50 70 3 84 63 37
35 86 23 63 79 89 48 22
100
56
3
1
3 16 1881 11917
48233 11933 53742
31630 57818 35460
897 440 983
579 162 597
1916
1
6 16 51577 4
47059 26620 59157 582 58780 19807
60097 28458 287 10757 55031 15727
1 1 1 1 1 1
1 1 1 1 1 1
3
Hint
Sample Explanation
For Sample #1:
-
For the first test case, you can spend a cost of to perform a bitwise AND with , meeting the requirement. It can be proven that no better solution exists.
-
For the second test case, it can be proven that no solution exists.
Data Constraints
This problem uses subtask bundling/dependencies.
- Subtask 0 (0 pts): Sample cases.
- Subtask 1 (10 pts): .
- Subtask 2 (20 pts): . Depends on subtask .
- Subtask 3 (20 pts): . Depends on subtasks .
- Subtask 4 (50 pts): No additional constraints. Depends on subtasks .
For all data, it is guaranteed that , , and .
京公网安备 11011102002149号