EOOPR Infinity 2020 Rated

What is the mistake in my solution ? someone will tell
ANSWER
for problem EOOPR Infinity 2020 A problem

if (x < y) {
			ll diff = y - x;
			if (diff % 2)
				moves = 1;
			else if (diff % 2 == 0 && (diff / 2) % 2)
				moves = 2;
			else
				moves = 3;
		}

You have forgotten 2 moves case

1 Like

possibility of ans=0 when both x==y

1 Like

Missed the case of 2 for x < y.
Take the example, X = 4, Y= 10. Minimum moves = 2

1 Like

No i did in last submsion ANSWER
sorry i will update solution link

how can moves equal to 3 is there any case ?

No, its still not there.
It should have been in case between lines 12-18 in your solution link.
Check again.

consider testcase x=10,y=12
ans=2 your is -> 3
u can add 1 twice to get y as 12

X=4 Y=12

Check case 2 10.
Adding 5 twice and subtracting 2 once. Can’t be done in lesser moves.

1 Like

easy case
0 6
+3 +3 = 2moves

Thanks got it

Answer is 2 when difference > 0 (or y>x) and difference is not divisible by 4, as when difference is not divisible by 4, the difference/2 term is odd, and can be chosen as a, and the entire moves required will be X=X+a twice, thereby leading from X to Y.
Example: X=1 and Y=3. If we take a=1, then two moves will be X = 1 + 1 = 2 for first move and X = 2 + 1 = 3 in the second move. This should be the minimum number of moves required in the given constraints.

Whereas, when difference is positive and is divisible by 4, difference/2 will be even, so the above case will not be applicable.

@zappelectro this problem is good but how find that coroner case in this type problems

when y>x and (y-x)\mod 4 = 0

thanks

1 Like

We felt this was quite an easy question for cakewalk, but it turns out that 3 moves case was pretty hard to find.

2 Likes

https://www.codechef.com/viewsolution/39308525
what’s wrong here?

add 7 ones and then add 1 more that will give y=10
(no no a will be same)

can you please give an example of 3 moves