athu18's blog

By athu18, history, 3 years ago, In English

During the contest I used Array of Integer type to avoid TLE, which can occur with array of primitive ints but that led to wrong answer but after I tried with array of primitives and I got AC. Can someone tell me why this is happening?

Submission 1: WA (https://codeforces.com/contest/1592/submission/130698133)

Submission 2: AC (https://codeforces.com/contest/1592/submission/130727745)

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

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

You are checking Integer objects for equality using !=, which is comparing the underlying references. This will usually work as desired for numbers in [-128..127] because these values are singletonized, but will rarely work as desired for any other numbers.