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

Автор AishwaryaR, история, 7 лет назад, По-английски

I've made a submission to problem 1303D. I get a correct answer when I iterate upto 30 bit positions, but, according to the constraints in the question, I've to iterate upto 60 (n: 1e18). I don't understand why the code reads junk bits (and hence increments variable splits) thus giving a WA.

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

»
7 лет назад, скрыть # |
 
Проголосовать: нравится +10 Проголосовать: не нравится

" if (n & (1<<it)){"

I think that 1<<it is considered an int, so 1<<(something bigger than 31) overflows and is treaded like a 0, so for it > 31 the condition is always false. Try using 1LL<<it or if((n>>it) & 1)