Блог пользователя Yuchang_Zhu

Автор Yuchang_Zhu, история, 21 месяц назад, По-английски

I'm so mad that C is wrong because I got the wrong data type!

  • Проголосовать: нравится
  • +3
  • Проголосовать: не нравится

»
21 месяц назад, # |
Rev. 2   Проголосовать: нравится +6 Проголосовать: не нравится

Don't be mad, take it as experience for later contests.

(Yesterday I used the wrong datatype for problem B, submitted and locked the problem immediately without optimizing the code. I was so careless and got TLE on test 9. After finished the contest, I just changed a few lines of code and it was Accepted. What a pity!)

»
21 месяц назад, # |
  Проголосовать: нравится +4 Проголосовать: не нравится

Join the #define int long long cult! Everyone hates us, and they got a point, but this kind of mistake won't ever happen to you again

»
21 месяц назад, # |
  Проголосовать: нравится +13 Проголосовать: не нравится

A good way to avoid these mistakes is to do a mental estimation of the upper bound of the absolute value before assigning datatypes. For example, if there's an array with $$$\le 2 \cdot 10^5$$$ elements between $$$-10^9$$$ and $$$10^9$$$, any subset sum of this array will be between $$$\pm 2 \cdot 10^{14}$$$, which clearly needs a 64-bit integer type. I try to be as specific about the bounds as possible, and it helps me verify my implementation as well, so I'd recommend others to do this too.

»
21 месяц назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Me too!