TopcoderArchiveVisit Topcoder
SRM17 Nov 2017
SRM 723

TopXorer

Problem statement, definition, constraints, and public examples.

Problem Statement

Like Topcoder, TopXorer uses a rating system. The rating of each person is a non-negative integer.

You are a coach. You want to select an n-person team. The team members will be labeled 0 through n-1. You have a set of constraints decribed by the int[] x with n elements. For each valid i, the rating of team member i must be between 0 and x[i], inclusive.

As the name suggests, the rating of a team in TopXorer is computed as the bitwise xor of the ratings of all team members.

You are given the int[]s x. Please compute and return the maximal team rating your team can have.

Definition

Class:
TopXorer
Method:
maximalRating
Parameters:
int[]
Returns:
int
Method signature:
int maximalRating(int[] x)
(be sure your method is public)

Constraints

  • x will contain between 1 and 50 elements, inclusive.
  • Each element in x will be between 0 and 1,000,000,000, inclusive.

Examples

  1. {2,2,2}
    Returns: 3
    One optimal solution is to select people with ratings (2, 0, 1). The team rating will then be (2 xor 0 xor 1) = 3.
  2. {1,2,4,8,16}
    Returns: 31
    This time the only optimal solution is to select people with the largest possible ratings.
  3. {1024,1024}
    Returns: 2047
  4. {7,4,12,33,6,8,3,1}
    Returns: 47
  5. {0}
    Returns: 0
Back to all problems