lvisbl_'s blog

By lvisbl_, history, 4 hours ago, In English

Recently I have done 711C - Coloring Trees, and I have found an overflow when I use min(a,b) function. More specifically, if I use:

min(a, b + c) when a, b and c are long long and sum of b + c large than 32-bit integer then the sum b + c will be treated as 32-bits integer and hence the overflow.

but let say, if I use a temporary variable:

long long tmp = b + c

then

min(a, tmp) will not overflow

What kind of behavior is this?

This is two submissions, one is overflow and the another one use a temporary variable will not overflow:

Overflow: 285989412

Not overflow: 286024512

  • Vote: I like it
  • 0
  • Vote: I do not like it

»
4 hours ago, # |
  Vote: I like it 0 Vote: I do not like it

Auto comment: topic has been updated by lvisbl_ (previous revision, new revision, compare).

»
73 minutes ago, # |
  Vote: I like it 0 Vote: I do not like it

I believe you are incorrect, if I add the line if (_k > k) return INF;, it passes 286068726.