Connection Status:
Competition Arena > TrueStatements
SRM 378 · 2007-11-20 · by bmerry · Brute Force
Class Name: TrueStatements
Return Type: int
Method Name: numberTrue
Arg Types: (vector<int>)
Problem Statement

Problem Statement

Professor Smith teaches a logic class. One day, he writes some statements on the blackboard:
Exactly a of these statements are true.
Exactly b of these statements are true.
Exactly c of these statements are true.
.
.
.

Each of a, b, c and so on is a number. He then asks the class how many of the statements are true.

You will be given a int[] statements, containing the numbers written in Professor Smith's statements. Return the number of the statements that are true. If there is more than one possible answer, return the largest one. If there are no possible answers, return -1.

Constraints

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

The 2nd statement is true (there is one true statement) and the others are false.

1)
{0}
Returns: -1

This is the Epimedes paradox: if the statement is true then it claims to be false, but if it is false then it must be true.

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

One solution is that the 3rd statement is the only true statement. However, it is also possible that the 2nd, 4th and 6th statements are true (all of which say that 3 statements are true), and the largest solution must be returned.

3)
{1, 1}
Returns: 0
4)
{1}
Returns: 1

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

Coding Area

Language: C++17 · define a public class TrueStatements with a public method int numberTrue(vector<int> statements) · 111 test cases · 2 s / 256 MB per case

Submitting as anonymous