Game of Deletion

3.1

14 votes
Basic Programming, Bit Manipulation, Bit manipulation, Medium, medium
Problem

Two players are playing the game of deletion. Player1 plays with array A and Player2 plays with array B. The length of both the arrays are N.
The game is like this - both of them want to delete their respective arrays. A player can delete the array in multiple steps.
During one step, he chooses some numbers from the array and takes the bitwise OR of these numbers and remove these numbers from the array.
This bitwise OR is the cost incurred in deleting the selected numbers. This way he deletes his whole array. The reward of deleting the entire array will be the sum of all numbers in the array minus the sum of the cost of all the steps.
The player with the maximum reward will win.

You have to print the winner along with the margin of reward he wins with. Let's say Player1 scored reward1 and Player2 scored reward2 and Player1 wins , then the margin will be reward1reward2.

Input
First line contains a number N . N is the length of the array.
Second line contains the N integers corresponding to elements of the array with Player1.
Third line contains the N integers corresponding to elements of the array with Player2.

Output
If Player1 wins, print 1 followed by a space and then the reward margin he wins with.
If Player2 wins, print 2 followed by a space and then the reward margin he wins with.
Print 1, if the game draws.

Input Constraints
1N105
1a[i],b[i]105

Sample Input
3
1 2 1
1 2 3
Sample Output
2 2
Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

Cost for deleting array A will be 3.
Cost for deleting array B will be 3.
Reward for Player1 will be 4 - 3 = 1.
Reward for Player2 will be 6 - 3 = 3.
Margin 3-1=2.
So, output would be 2 2.

Editor Image

?