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

Автор TheDutchLion, история, 5 часов назад, По-английски

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

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

»
5 часов назад, # |
  Проголосовать: нравится +6 Проголосовать: не нравится

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.