C:Two Array. How to optimize my code?

Правка en1, от ritik_patel05, 2020-01-15 22:42:40

Problem : https://mirror.codeforces.com/contest/1288/problem/C

My solution: https://mirror.codeforces.com/contest/1288/submission/68821660

Can anyone tell while I calculate dp[pos][i][j], I am using O(n*n) to calculate for each pair. Can I optimize by using some precalculated sum array, as we do in 1D case to get the sum for a particular range in an array?

In my code, I have written this, //to calculate dp[pos][i][j] //using dp[pos — 1][previ][prevj]

How can I do this in O(1) to fit in timelimit?

I am thinking about this optimization for a long time, but I got to nowhere.

It would be great if there is any way to do it.

Thank you :)

Have a great day!

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en1 Английский ritik_patel05 2020-01-15 22:42:40 728 Initial revision (published)