Connection Status:
Competition Arena > WhiteHats
SRM 361 · 2007-08-01 · by slex · Brute Force, Simple Math, Simple Search, Iteration
Class Name: WhiteHats
Return Type: int
Method Name: whiteNumber
Arg Types: (vector<int>)
Problem Statement

Problem Statement

There is a number of people in a room, and each of them wears a hat which is either black or white. Every person counts the number of other people wearing white hats. You are given a int[] count, the i-th element of which is the number counted by the i-th person. Return the total number of people wearing white hats, or -1 if count doesn't correspond to a valid situation.

Constraints

  • count will contain between 2 and 50 elements, inclusive.
  • Each element of count will be between 0 and 50, inclusive.
Examples
0)
{2,1,1}
Returns: 2

The first person wears a black hat and sees two people wearing white hats. Each person wearing a white hat sees only one other white hat in the room.

1)
{2,2,2}
Returns: 3

Everyone wears a white hat here.

2)
{0,0}
Returns: 0

Black hats only.

3)
{1,1,1,2}
Returns: -1
4)
{10,10}
Returns: -1

Now that's interesting. There are only two people in the room, yet each of them counted 10 others.

Submissions are judged against all 158 archived test cases, of which 5 are shown here. Case numbers match the judge’s.

Coding Area

Language: C++17 · define a public class WhiteHats with a public method int whiteNumber(vector<int> count) · 158 test cases · 2 s / 256 MB per case

Submitting as anonymous