# Best spot

# Best spot

+ 0 comments can some one explain me the question?

+ 0 comments Can someone suggest me ways to optimise my code ?

r, c = map(int, input().split()) l, t, smallest_sum, point = [], [], None, None for i in range(r): l.append(list(map(int,input().split()))) h, w = map(int, input().split()) for i in range(h): t.append(list(map(int,input().split()))) for i in range(r-h+1): for j in range(c-w+1): temp_sum = 0 for m in range(h): for n in range(w): temp_sum += (l[i+m][j+n] - t[m][n])**2 if smallest_sum == None or smallest_sum > temp_sum: smallest_sum = temp_sum point = i,j, print("{}\n{} {}".format(smallest_sum, point[0]+1, point[1]+1))

+ 0 comments Can anyone help me ! this is my code for the problem

def bestSpot(heights, store): # # Write your code here. divide = (len(heights)-len(store)+1) ar = [0] * pow(divide,2) for i in range(len(ar)): for x in range(len(store)**2): ar[i] += pow(heights[int(i/divide)+int(x/len(store))][i%divide + x%len(store)] - store[int(x/len(store))][x%len(store)],2) print(min(ar)) print(int(ar.index(min(ar))/divide)+int((len(store)*2 -1)/len(store)),ar.index(min(ar))%divide + (len(store)*2 -1)%len(store)) #

However, i dont know what wrong with this code, i try on paper and it is correct, but when submit, it fail

+ 0 comments i don't understand the question exactly.So,Someone helped me to sort the question?? Question is-In Chile, land are partitioned into a one large grid, where each element represents a land of size 1x1.

Shaka is a newcomer in Chile and is trying to start his own business. He is planning to build a store. He has his own ideas for the "perfect store" which can be represented by a HxW grid. Element at position (i, j) represents height of land at index (i, j) in the grid.

Shaka has purchased a land area which can be represented RxC grid (H <= R, W <= C). Shaka is interested in finding best HxW sub-grid in the acquired land. In order to compare the possible sub-grids, Shaka will be using the sum of squared difference between each cell of his "perfect store" and it's corresponding cell in the subgrid. Amongst all possible sub-grids, he will choose the one with smallest such sum.

+ 0 comments Hi,

I am getting "Timed Out" for the test cases 8, 10, 15, and 20-29. However, the simulation completes successfully for all the test cases except 8, 10, 15, and 20-29 on this site. Moreover, the test cases 8, 10, 15, and 20-29 runs fine on my machine. I followed a rigorous searching method using “for loops” by selecting a matrix of size HxW from RxC and moving the matrix. After viewing the input files for the “Timed Out” test cases, I am assuming that for bigger input files the program is taking longer time to finish. Now, I was wondering whether there is any way to bypass this “Timed Out” by increasing the cap.

Thank you.

Sort 8 Discussions, By:

Please Login in order to post a comment