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

Автор jha_gaurav98, история, 6 лет назад, По-английски

What will be the time complexity of the following nested loop:

for(int i=2;i<n;++i){
    for(int j=i;j<n;j+=i){
        //some code here
    }
}

Actually I was participating in a competition on Codechef last night. And there was a question for which I thought of a solution like this. But the range of n was [2, 106] and time limit was 1.5s. So I thought that my solution will exceed the time limit and hence I didn't submit it. But after the contest I saw another guy submitting the same solution and getting his solution accepted. So, can someone tell what is the exact time complexity of this code snippet?

Link for question

Thanks in advance

Полный текст и комментарии »

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

Автор jha_gaurav98, история, 6 лет назад, По-английски

Given a square array of size N × N where each cell is filled with a number between  - 9 and 9. A sub square of size k is any set of k contiguous columns and k contiguous rows. For any sub square, the sum of elements in its cells is called a sub square sum. Given the N × N square, write a program to find the maximum sub square sum. (Note that a 1 × 1 square (k = 1) is not considered a sub square)

Constraints: 2 ≤ N ≤ 1000

By looking at the constraints I think we have to do it in O(N2). I could manage to reach to O(N3). Please Help

Thanks in advance

Полный текст и комментарии »

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

Автор jha_gaurav98, история, 7 лет назад, По-английски

I am organizing a contest for my college students. For this I thought of a basic graph question. In order to generate the test cases , I used random number generator. But I am not able to generate the output as when I try to run it on my computer it runs out of memory.Can anyone please tell how to run programs with big inputs and outputs? And also is there any other effective way of generating the test cases except the random number generator? Thanks in advance.

Полный текст и комментарии »

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

Автор jha_gaurav98, история, 7 лет назад, По-английски

I was solving the question PSHTRG. Basically it is a segment tree problem. I stored 45 greatest elements of each range as the node in segment tree and then for each query I used these elements to find the answer. But my code is giving TLE. I think there is nothing wrong with the logic but I am not able to optimize the code. Please can someone help. Thanks in advance.

Полный текст и комментарии »

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

Автор jha_gaurav98, история, 7 лет назад, По-английски

I recently encountered a question QTREE on SPOJ. Initially I had no idea how to solve the question. After a bit of googling , I found that there is something called heavy-light decomposition which is involved in the question. But I was unable to find any resource which can explain this topic in an easy manner. Please if you know some resource where it is explained comprehensively and in easy way , please tell me.

Полный текст и комментарии »

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