TrueStatements
SRM 378 · 2007-11-20 · by bmerry
Problem Statement
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
Constraints
- statements will contain between 1 and 50 elements, inclusive.
- Each element of statements will be between 0 and 50, inclusive.
{0, 1, 2, 3}
Returns: 1
The 2nd statement is true (there is one true statement) and the others are false.
{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.
{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.
{1, 1}
Returns: 0
{1}
Returns: 1
Submissions are judged against all 111 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
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