Mothaiba's blog

By Mothaiba, 10 years ago, In English

Recently, I tried to solve problem 121C, but some weird things happened

Here is my 2 submissions

7567786 7567793

The first one gets AC, the second one gets TLE. The only difference between these 2 is in the second, i add " // " at line 77, at where the code line " cout<<" " ". Thus, if I cout<<" " at each loop, the result is OK, but if not, something happens and I get TLE. Please explain me! Thank you very much!

  • Vote: I like it
  • +3
  • Vote: I do not like it

»
10 years ago, # |
  Vote: I like it +13 Vote: I do not like it

Please explain me!

undefined behaviors all over the place. I wonder how one of this submissions got AC, it's kind of miracle

»
10 years ago, # |
  Vote: I like it +4 Vote: I do not like it

On line 95 you use the variable j without initializing it.

Also you should be careful with log10(), it can return imprecise floating point values, and you may not get what you expect when converting the value to int.

  • »
    »
    10 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Thanks for your response!

    I forgot what happened when I used pow without epsilon last time...

    But still, does cout command affect the initial value of variable? or something like this?

    • »
      »
      »
      10 years ago, # ^ |
        Vote: I like it +1 Vote: I do not like it

      When you invoke undefined behavior, you can expect any weird thing to happen.

      On the machine code level, this is probably because calling operator << accidentally leaves a zero in the register or memory area where j is supposed to be, and the program appears to work.