duckmoon99's blog

By duckmoon99, history, 8 years ago, In English

I'm not sure if this is a bug, but would like to know why is this wrong.

http://mirror.codeforces.com/contest/761/submission/24331207

http://mirror.codeforces.com/contest/761/submission/24331035

Both of these codes are the same except one defines INF as 10e9, and the other as 1000000000. Yet one gets WA and the other didn't. Why is this? Thanks :)

Tags bug
  • Vote: I like it
  • +1
  • Vote: I do not like it

»
8 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Good day to you!

Well because "temp" might not be initialized when you use it:

if(i != j && j != k && i != k){
    temp = num[i] + let[j] + sym[k];
}
if(temp < INF){
    ans = min(ans, temp);
}

If the first condition is not "OK" and temp was not set yet, it could bring in an undefined value (such as -INF).

Setting it to INF shall get you AC.

But no clue whether the change of inf can influence it somehow (but as you can see, those INF's are different numbers, so perhaps something "in your code" [first inf is 10^10 second just 10^9] )

Good Luck & Have Nice Day.

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

    That's brilliant! Can't believe I made such a stupid mistake, thanks a lot! :)

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

    However on the code defining inf as 10^9 and did not initialize temp either, not sure why did that AC. :/

»
8 years ago, # |
Rev. 3   Vote: I like it +30 Vote: I do not like it

10e9 is actually 1010. Try defining INF as 1e9.

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

    Still doesn't work. It's as Morass said, I did not initialize the value of temp. But thanks anyway!

»
8 years ago, # |
  Vote: I like it +3 Vote: I do not like it

bool trump[3];

Trump Supporter detected.