Editorials should be made simple

:joy::joy::joy::joy:

…,…

1 Like

I think they should not keep long templates right ?
Is that what you mean to say ?

Can you post the link to the contest from which you said you found the probs of this JUNE challenge?


:joy::joy::joy:
At first it seems weird to everyone.
You can read about it here.

But I think a bit comment on tester,setter solutions can help a lot.

1 Like

Whenever i’m not able to solve a problem in a live contest i feel really bad and become sad. But i always take this as a silver lining. That is, if i’m not able solve a problem i’ll have to see the editorial later and i’ll learn new tricks. That seems cool to me.

If the level of editorial is within your reach, will you be able to get out from your comfort zone ? will you learn new tricks and things?

4 Likes

Can anybody help me find out the reason for TLE in this, I used the approach illustrated in the editorial. https://www.codechef.com/viewsolution/24861538 , the editorialist’s solution in same as your’s @l_returns , can you kindly help me with this?

XD :rofl::rofl: [20 char curse]

Isn’t this O(n) in worst case ?
int ct[c]={}

Wait… if i initialize an array with an empty bracket shouldn’t that by default initialize every element with zero in constant time?
Moreover if it does take O(N) time then why does sub-task 3 passes?

EDIT : Ok so i searched about it a bit, it turns out this is not a constant time operation (now
i feel like an idiot, that didn’t knew a thing this basic, been using this all the time.
Though initializing like this will not take worse time than memset or loop, its usually faster then those two.

I still don’t understand why does the 2nd ans 3rd subtask gives AC as the number of distinct elements ( = c in my program ) can be n/2 in worst case which makes this an q*n algo.

1 Like

Is it ?
I just declared the array outside and used memset and time taken reduced from
3.88s to 1.26s
Will try removing memset later.
I still thinks it’s memset which requires optimization.
Let me try.

It’s simple
“Weak test cases + strong optimizations”
XD

Yeah and you know who is author of that link ?
@aryanc403 himself :stuck_out_tongue:
He makes editorials in Russian using Google translate and then solve questions :joy:
I am not sure about this though but one thing he does for sure
he add’s it to “robot.txt” so that you can’t find it using Google :stuck_out_tongue:

1 Like

Wtf! :joy: :joy::joy::joy::joy::joy:

:joy::joy::joy::joy::joy:
OK so, what can i do to improve this? I am essentially using the same approach as the editorial, i replaced the array ct[] with a map but that increased the time instead.
Even though using map the complexity is Q√n (compared to Qn using ct[] array), so i guess that’s because of weak test cases.
Even though 1-3 subtask takes only 1.4sec or so last subtask times out.
Any help is appreciated.

Can anybody suggest me some good set of problems and solutions of Graphs/trees along with DP ? Video links would be of great help. :confused:

Try this out

6 Likes

If you have the time, then I have one more query :sweat_smile:
I noticed that when you declared some variables outside the loop in my program the execution time decreased quite a bit, I have read about this before and almost every answer on stackoverflow states that it’s best to keep variables as close as possible to their scope and this does not affect the execution time. But in this case this doesn’t seems to hold. Of course if we are using same value in every iteration it would be best to declare it outside the loop. But in this case that’s basically the same thing, we are calling memeset anyway.
Are there any cases where i shall actually prefer declaring them outside ? (to bypass a tight TLE)

I think allocation of memory in a loop is bad.
As it will have to redeclare it again and again in runtime.
Hence I took it outside.
I keep it outside.
I am not sure if keeping it in loop optimizes code.
One optimization is declare it as static
It reduces running time.

I read that modern compilers automatically prevents re-deceleration, but i guess that might not be true for all cases. Thanks Anyway!
Btw do you have any tip to optimize my code? complexity would be fine if i use a map
( N √n , even though it takes more time :rofl: ) .

EDIT: finally AC, all i had to do was assign ct[]'s used places back to 0 while calculating the answer, this makes it q*√n again. XD this was so simple yet took so much time :joy:.
Thanks for your help mate!

Glad that I could help !!

Yup that is what I do generally
:slight_smile: