MinimumLiars
TCO11 Qual 1 · 2011-05-07 · by vexorian
Problem Statement
Now, given a
Constraints
- claim will contain between 2 and 50 elements, inclusive.
- Each element of claim will be between 0 and 100, inclusive.
{1,1,1,2}
Returns: 1
It would be impossible for all the members of the group to be honest because in that case, all of their answers would be 0. It is, however, possible that only the last person is a liar and each of the first three persons is honest. Therefore the correct answer is 1.
{7,8,1}
Returns: 2
The first two people claim that there are at least 7 and 8 liars, respectively, which is impossible as the group only has three people. Thus, they must be lying. The third person claims there is at least one liar, and this is definitely true since we have already identified two liars, so this person is honest.
{5,5,5,5,5}
Returns: -1
Everybody agrees that there are at least 5 liars in the group. The group contains exactly 5 people, so in fact all of them claim that everybody is a liar. We can't assume that some person is honest because this person definitely wouldn't have claimed him/herself as being a liar. We also can't assume that all of them are liars because in this case it will appear that all their statements are true. Every scenario we can try leads to a contradiction, so you must have misunderstood at least one of the answers.
{0,0,0,4,3,0}
Returns: 2
{0,0,0,0,0,0,0,0}
Returns: 0
{4,7,5}
Returns: 3
Every claim made is impossible. Therefore all three people in the group must be lying.
Submissions are judged against all 205 archived test cases, of which 6 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class MinimumLiars with a public method int getMinimum(vector<int> claim) · 205 test cases · 2 s / 256 MB per case