Boring_Day's blog

By Boring_Day, history, 21 month(s) ago, In English

Lets say you have a matrix. Write a function which takes cell points and a number k. (It returns sum from rows).

for ex: func(i, j, k) here i and j are cell position. And k is a number. // I want sum from continuous rows.

I want sum from mat[i][j-k] to mat[i][j+k] + sum from mat[i-1][j-(k-1)] to mat[i-1][j+(k-1)] + sum from mat[i-2][j-(k-2)] to mat[i-2][j+(k-2)] and so on. If you go out of border add zero (do nothing).

Help me please Tell me if i clearly explai the problem or not.

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

| Write comment?
»
21 month(s) ago, # |
Rev. 2   Vote: I like it +1 Vote: I do not like it

It is important to mention that k is constant every time we call the function but not the i and j. So we need to do the pre computation. Help sir, tfg

  • »
    »
    21 month(s) ago, # ^ |
      Vote: I like it +50 Vote: I do not like it

    Why on earth did you ping me specifically?

»
21 month(s) ago, # |
  Vote: I like it -11 Vote: I do not like it

You want to take the sum of this triangle: https://i.328888.xyz/2023/04/14/ixDSDx.png

We could actually just take the left half of the triangle, and then for the right half, we could just flip the whole array left and right and apply the same algorithm.

https://i.328888.xyz/2023/04/14/ixU0VN.png

So you just have to figure out the sum of all the x's and y's, the orange part, and then you can figure out the sum of the triangles.

  • »
    »
    21 month(s) ago, # ^ |
      Vote: I like it +9 Vote: I do not like it

    What is the orange part? How to figure out x's and y's. And how is it actually giving us the sum of one part of triangle. Hard to understand 😖