I have a doubt in D ques

I know it can be solved via graphs,but I tried it in a different approach and It did satisfy all the given test cases.But then I got an error:

wrong answer Integer parameter [name=res_41] equals to 6661498349661025390, violates the range [1, 3000000000000000000]

My submissions:

1st submission

2nd submission

3rd submission

4th submission

__int64 and long long are same in space requirement,then what’s wrong?

Please help me…what is wrong in my approach?

TRY THIS TEST CASE

**3**

**9000 1000 3000**

**YOUR OUTPUT - 9000 3000 123960450479594**

**CORRECT OUTPUT - 9000 3000 1000**

Can’t we just sort the numbers based number of factors of 2 and 3.

We can sort the numbers based on increasing powers of two then among the numbers which contain same power of two sort in decreasing order of power of 3.

Seems like a simple logical error is restraining you from AC.

Your 1st submission, now AC

Oh wow…thanks a lot…but…why were those lines of code creating problem?

I mean…I thought -

if (a[i] == s)

continue;

is required so that it doesn’t check with itself!

You would `continue`

on a[i] == s if it determines any ‘special’ condition, like if you have already added it’s decendents (s // 3 or s * 2) into your answer vector(v). But since you haven’t so its decendants needs to be checked and it is to be treated like every other element in the original array.

Thanks a lot…I understood it now!

1 Like