Lessons learned from solving weirdo (as well as solution)

Could u tell why m getting tle in substask 1
And ac in rest
I used same approach as mentioned in thread
https://www.codechef.com/viewsolution/27867163

The same happened with me .
would be great if someone helps !
To get full score i just pust if statement and copied my solution for subtask 1 :sweat_smile:

1 Like

Same here :slight_smile:

WEIRDO - “From Zero to Infinity” - documented code; Editorial-style overview

I was also toying with the whole prime factorisation approach, but thankfully - and slightly surprisingly - using logs turned out to be accurate enough :slight_smile:from-zero-to-infinity-git-log

5 Likes

Fantastic. I will study your code in detail actually. Since I was struggling in the input processing phase too. :slight_smile:
Thanks for sharing!!!

here’s mine

btw also check out @ssjgz code also, it’s pretty neat

3 Likes

Here is explaianation…

3 Likes

Heavy input processing in task 1.

I was facing same issue when I was using maps to shore character frequencies (check here): CodeChef: Practical coding for everyone

Then I changed my code to use vector and got AC.

Many people did wrong to check whether a string is of Alice or Bob , they just count vowels and conso and check if vowels are greater than equal to conso then it will be of Alice else Bob which is Wrong

Instead of this we have to count vowels and conso in each three consecutive character of string .

1 Like

I used a completely different approach.

take a look here

I was getting AC for subtask 1(1.41s) and WA for subtask 2. I changed from maps and strings to arrays and got AC for subtask 1(0.2s) and WA for subtask 2. Finally on using cpp_dec_float_50 to find the final answer I got AC for subtask 2. Have a look here

https://www.codechef.com/viewsolution/27868379
Did all the things mentioned here still don’t know what is wrong. Please anybody look at this.
Tried everything i knew boost etc.

Though i thought of the same approach but won’t there be cases where the resultant will be small but the power function overflows

Do not calculate power buddy see my solution above mentioned I did not calculate power bcz it will overflow

3 Likes

You don’t need power, just three basic log properties

log(a^b) = b*log(a)

log(a/b)= log(a) - log(b)

log(a*b)= log(a) + log(b)

Use them on the expression to get it into a one line formula which doesn’t need powers but logarithms

3 Likes

Fantastic. I studied it in detail. From a debug perspective, can you explain the purpose of assert(cin) in the last line?

1 Like

It’s just to ensure that I haven’t accidentally tried to read more input than exists, or e.g. tried to read a string as an int or somesuch - something that has bitten me a few times in the past :slight_smile:

Edit:

Also helps to make sure that my testcase generator generates the right amount of stuff and of the right type.

3 Likes

Thanks for the explanation! Would you mind if I mimic some elements of your style, since emulation is the highest form of adulation! :slight_smile:

1 Like

I would be honoured :slight_smile: Please take anything you want :slight_smile:

Edit:

I gabbled on about my process here, and included the code template I usually use. Bear in mind that I don’t do short contests, though - the process really wouldn’t be suitable for those :slight_smile:

1 Like

Fantastic. Good practices to be learnt!

1 Like