adarsh000321's blog

By adarsh000321, history, 5 years ago, In English

Hello Codeforces, I actually have two codes (69520703 and 69521121) that are doing the same thing but i just changed the order of the states and one of them is giving TLE (at test case: 78)and the other got AC. Can you please help me out. Dislike if you want but please reply :)

  • Vote: I like it
  • +12
  • Vote: I do not like it

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

Could Someone take a look at it. I've been stuck here for more than 4 hours. Please

»
5 years ago, # |
  Vote: I like it +10 Vote: I do not like it

I'm guessing cache.

»
5 years ago, # |
  Vote: I like it +10 Vote: I do not like it

Cache friendliness is one possible reason.

Another reason would be that in Java, memory of a multidimensional array are not allocated in a contiguous block, so new int[a][2] would create a small blocks of memory each contains a int[2]. In comparison with new int[2][a], that's a lot slower.

new int[2*a] should be faster (but also harder to read)