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

Автор Shreyansh_1347, история, 11 месяцев назад, По-английски

I exactly implemented the tutorial for the problem G. Hits Different. The solution they gave looks like they have the same time complexity as mine. But still, I get a TLE on test case 2. My Submission

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

»
11 месяцев назад, # |
Rev. 2   Проголосовать: нравится +7 Проголосовать: не нравится

Pass by (const) reference unless you have a reason not to do so.

»
11 месяцев назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

They did a precomputation of the main algorithm that you are doing every time for every test case. The time complexity for your solution is ~ T * (1500*(1500+1)/2) (considering the nested for loops in solve() and the loops in sum() function). So in the worst case, it goes upto ~1.125 * 1e9 number of iterations. What the solution does is it precomputes the main algorithm in ~1.125*1e6 and then for each test case, it is performing an O(1) operation. So in the worst case, it won't exceed 2.5*1e7 which is roughly 2.5sec (if I take 1e7 iterations in one sec).