TTUPLE - Editorial

Of course. It was giving SIGFPE before that.

well since everyone was sharing their long submission for this question so I am also here to show mine code as well (580 lines) :rofl: :rofl: :rofl: :rofl: :rofl:
https://www.codechef.com/viewsolution/33804457

1 Like

thanks

share a link instead of posting hundreds of lines of unformatted code

Bro u still wrote a short Code !! I wrote around 500 lines :rofl:

1 Like

how can I test my own solution if tester solution is wrong it self
I found it wrong on many cases like:
0 0 2
2 1 4

0 1 0
2 1 4

and many other cases
In above cases tester code shows result as 3
but editorial code shows result 2

A simpler approach to avoid missing any condition :

It is easy to check if answer is 0 or 1. so let’s focus on how to check if answer is 2.

If answer is 2, then in the optimal approach

Case 1 : If All the elements require 2 operations, then this operation will be multiplication and then addition. (Try to think why). So we just find the value to add and multiply from first two elements and then check it in the third one.

Case 2 : If Any one element requires only 1 operation, then there are 48 possibilities.

3 possibilities on which one requires 1 operation.
2 possibilities on which operation is required add/multiply.
2 possibilities on whether it is the first operation or the second operation.
4 possibilities on of subset remaining two elements.

We can implement all of them easily, let’s see by example.

If I make a equal p in first operation, by adding x, a and b are in the subset, transition is : res = min(res, 1 + solve2(b + x,c,q,r)

If I make b equal to q in second operation, by multiplying x, b and c are in the subset, transition is :
res = min(res , 1 + solve2(a,c,p,r/x)

So here you see the trick, to apply the second operation, we can just make change in (p,q,r) and for first operation, make change in (a,b,c).

Note : Don’t forget to check conditions for divisibility.

Here is my submission with comments : Submission

4 Likes

posting my solution too: CodeChef: Practical coding for everyone

it is 747 lines long :slight_smile: so I guess I take the award for the messiest and most incomprehensible sol so far

4 Likes

Cases like :
p = 2 * a , q = 3 * b , r = 6 * c
gets covered in the above 2 cases?

Yes, I am sending a neat submission in a while.

My solution kind of based on @nishant403 explanation above CodeChef: Practical coding for everyone. The quality of code can be improved.

1 Like

Sed lyf bro :frowning:

i see que obviously instantly got we have to do brute force after 5 min make 4 diff cases for ans=2 code in 5 min got an WA leave the contest THIS WAS THE WORST QUE EVER THEIR WAS NO USE OF BRAIN!!! SORRY FOR BEING SUCH AN IDIOT :slight_smile: !!

2 Likes

thanks bro! it really helped. gonna add few more conditions
:sweat_smile:

i was trying to print answer 0,1,2,3 because only these four number could be the answer.Still got wrong answer :frowning:

You’re a genius bro! Please gib me sum teeps and treeks

anyways… its okay. thank you for your reply…
May be I was the unlucky one to have some microscopic level test case missing
:upside_down_face: i have faced such cases before.
But I think that I should concentrate more on the editorial solution now because this is how we make proper use coding, to work less ourself and let the machine think of all the cases. That’s what programmers do. :relieved:

No! There’s a guy with more than 1000 lines of code and that too is not passing first subtask. :joy:

Can anyone explain why did we need to add 0 to mult set?
Because if 0 was a valid choice of multiplication i.e. if any ratio b[i]/a[i] ==0 was present in the test case, it would have counted. So why are we adding 0 exclusively?
@rajarshi_basu?

My code has passed all test cases and edge cases still I’m stuck at 10 points :frowning:
This is my code:- https://www.codechef.com/viewsolution/34420341
Can anybody suggest a possible correction or test case which I couldn’t figure out!?