TheDutchLion's blog

By TheDutchLion, history, 5 hours ago, In English

I have recently encountered a problem where my solution that used a vector of size n * n * m was giving TLE whereas when i changed the dimension to m * n * n it got accepted.(I kept the remaining logic and the rest of the code same).

Question 2057E1 - Another Exercise on Graphs (Easy Version)

TLE solution 301118680

ACCEPTED solution 301119202

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

»
5 hours ago, # |
  Vote: I like it +6 Vote: I do not like it

In the second case CPU can better predict memory accesses and thus supply data from memory at a higher rate. You are always better off processing arrays sequentially, e.g. if you process two dimensional array dp[i][j] using nested loops then your inner loop should iterate over j, not i.