Someone Please explain the difference between these two solutions for Compression Algorithm

What I meant was in his questions both formulas are correct but when he posted another screenshot in the comments(look at his comment) , where he used ‘n’ instead on ‘n-1’!!otherwise in his original screenshot both are correct I guess its just about absolute error and sometimes it happens when they calculate absolute instead of relative error!!

2+((n-1)(k-1)2)/k
=2
(1+(n-1)(k-1)/k)
=2
(k+(n-1)(k-1))/k
=2
(k+nk-n-k+1)/k
=2
(n*(k-1)+1)/k
Please analyse before you comment

2 Likes

@swetankmodi check my above simplification. The two formulas (the original question one and the commented one) are interchangeable.

@rishi_07 thanks for this derivation. Even I told my teammate that this was wrong. Holy shit XD

@horizon121 please be review @rishi_07 's comment. I hope @admin takes a look at this.

Yes yes, actually my teammate was convinced that he had made a mistake in simplifyying the recurrence, so I commented without verifying it the second time. My bad. Thanks for this derivation!

Sorry about the formula I didn’t see that . Now when I looked closely you used setprecision(10) it does not guarantee that your answer will have 6 decimal places you need to use ‘std::fixed’ before setprecision if you want precision upto 10 decimal places.

FYI: I used fixed, still no good. Someone please explain us the error :confused:

+1 to this

My words precisely!!. And YES, LAST YEARS SET WAS <33333333333333

2 Likes

You should have used a higher precision (like cout <<fixed<<setprecision(30)<<endl; or use fixed point notation by using cout<<fixed<<setprecision(7)<<ans<<endl;

You should have used a higher precision (like cout <<fixed<<setprecision(30)<<endl; or use fixed point notation by using cout<<fixed<<setprecision(7)<<ans<<endl;

2 Likes

I agree with you that using relative error could have been a better decision. It made situation harsh with some participants. During testing, we used either fixed precision and didn’t think such issues can arise.

2 Likes

@admin but our code gives correct answer for the testcase you provided in the other post. (Submission ID: 16117083). Please recheck the issue.

@admin - We even tried setprecision(15), still WA. It’s really disheartning to see similar solution getting AC when there is only difference of setprecision. :frowning:

I thing using ios_base disables the auto-sync after every IO operation. So if you use printf, only then it will explicitly sync with c and c++ stream and not after every cin/cout. (I may be wrong though)

In one previous comment stating about 600solved the pblms ok where they ordered based on who found the algorithm first to say truth it’s no I even had a personal experience where our team got the algorithm first but my friends team got the code right before and the time difference was more than 3/4 hrs,and the even annoying part was interanal error which even reduced our confidence level .

Its a bit of difficult derivation. The inspiration is, -

Total possible strings are {K}^{N}. Now, think of strings with block of 1,2,3… and so on.

You will get a formula which is is nothing but differential of x*{(1+(k-1)x)}^{N} . The first half isnt known to me, my teammate derived that - I resumed from this differential part and completed the formula for him :3

I derived a recurrence and solved it using generating functions. It’s like 2 pages long, you want me to post or someone with an easier solution would be willing to help?

Use fixed. And also change 1 to 1.0 everywhere