This is the problem : http://www.codechef.com/ACMAMR12/problems/ATKCTR
And my solution is : http://www.codechef.com/viewsolution/1753450
It is giving wrong answer!! Kindly suggest how to correct it?
This is the problem : http://www.codechef.com/ACMAMR12/problems/ATKCTR
And my solution is : http://www.codechef.com/viewsolution/1753450
It is giving wrong answer!! Kindly suggest how to correct it?
Your logic is incorrect. In case there is an attack which beats all other attacks, answer is 2, and note this attack can be different from attack N.
In case no such attack exists answer is 1. Answer will never be zero since if opponent’s attack can’t be beaten by any attack, I would have chosen that attack in the first place and got a score of 2.
you can consider the approach is as follows : 1. if there are no anomalies, solution is ‘2 N’. 2. if there are anomalies, the logic to find most powerful power[i] is : (a) the number of anomalies where it wins is (N-i) && (b) the number of anomalies where it loses is 0. then the solution becomes ‘2 i’. 3. you would have realized that there is no way that Gandalf is going to lose. so, if both (1) and (2) didn’t fetch any result, solution is ‘1’.
frankly speaking, your approach is correct. could have done it in more efficient way.
the mistake i see is that you don’t do anything once you got that genuine ‘maxattack’.
once you got that ‘maxattack’ you need to print ‘2 maxattack’ right !!