Molecular Mass

I’m failing 5th time for test case 10(hidden). Can any one explain how to solve this problem. There is also
no editorial available.

problem link:-link text

my solution link:- link text

According to problem statement what will be mass for ((((HH)3)4)C3)6

1 Like

(HH)= 1$+1 = 2 (HH)3 = 23 = 6 ((HH)3)4) = 64 =24 C3= 123 = 36 ((((HH)3)4)C3) = 24+36 = 60 ((((HH)3)4)C3)6 = 60$6 = 360
This should be the solution according to what I understood…

How come C3= 12*3= 24 it should be 36.

((((HH)3)4)C3) = 24 + 36=60

((((HH)3)4)C3)6 = 60 * 6=360

so final answer comes to be 360

My code produces 360 still WA. Help me

yeah correct…

so was this test case there in their test cases or this is just an example from you ?? was this test case found wrong by them ?

its an eg. i wanted to check whether my algorithm produces correct output or not. Now I want to know for which test case my algorithm produces wrong o/p. As I submitted five times and always it fails on 10th test case(hidden).

1 Like

can you explain your logic a bit ??

((CH3)2(CH2O)(O3)2)2(OH)
check this one

for all characters except ‘)’-> push into stack

for ‘)’ --> pop from stack, and adding molecular mass of popped element until most recent ‘(’ is encountered at top of stack.

Now after every pop() operation I checked whether immediate next element is digit or not.
because if its a digit(n) then that implies the entire group{from ‘(’
to ‘)’} which recently poped is repeated n times. So my mass will be n*mass.

While popping from stack if digit(n) is encountered(top of stack) and immediate character is an element(let say H) so i have added mass of H ‘n’ times.

1 Like

Output according to me should be 329 and your code is giving 449

@l_returns
((CH3)2(CH2O)(O3)2)2(OH) – 449 my code produces.

simplification
((C2H6)(CH2O)(O6))2(OH)
(C3H8O7)2(OH)
(C6H16O14)(OH)
(C6 H17 O15)
6$12 + 17 + 15$16
72 + 17 + 240 = 329

your code is correct when we input a bit simplified version
((C2H6)(CH2O)(O6))2(OH)

So now can u say where my am i missing in algorithm. can u design algorithm for this problem

I can try… i ll reply as soon as i get it…

Thanks plz revert back when u get it. Thanks once again

1 Like

What i found was… ((H)2©3) here in this test case you added H 6 times which should not be the case… the 3 is only multiplied with C and not H… so here is the problem in your algo…

1 Like

I suggest you to solve your mistake if u can… I already tried to help u in finding where u r going wrong…
Though I can try and I think I can solve this error if u want me to…
but I strongly recommend you to solve it yourself because its better that way…
Competitive programming is about learning how to learn and that is(solving ur problems( i.e your bugs) by yourself) what you learn from it…

PS: I think you can solve this error (by seeing ur level of coding)… you just need some determination…
But do let me know if u want me to solve it…

and thanks for pointing out my mistake of multiplication in above calculation

I updated my algorithm now it solves all above mention formulae by u correctly but still fails for sixth time :frowning:
I have updated my solution link above .
So can u plz point my mistake or give corner case for which my code fails so again i can update by this way eventually i would get it AC