Questions Tagged With #codechefhttps://discuss.codechef.com/tags/#codechef/?type=rss&user=raminiquestions tagged <span class="tag">#codechef</span>enSun, 26 Nov 2017 00:33:35 +0530My approach for SMRSTR(November Lunchtime)https://discuss.codechef.com/questions/118563/my-approach-for-smrstrnovember-lunchtime<p>Problem:- <a href="https://www.codechef.com/LTIME54/problems/SMRSTR">SMRSTR</a></p>
<p>It says that we have to optimize the code snippet given in the problem. We can observe that for every value in the X array we do the same thing by dividing it repeatedly by all the elements in the D array i.e we just divide every value in the X array by the product of all elements in the D array. So, we can proceed by finding this product only once. But according to the constraints the product results in a very big number. But we can observe that if product is greater than the largest element in X array, then answer becomes zero for all of them. So, we stop calculating the product when it crosses the largest element in X array. Since, largest element in the X array satisfies our constraints, we can ensure that our product doesn't overflow. If the product does not exceed the largest element of X array we simply find it and divide it with all the elements of the X array and print the result. This gives us a runtime of O(n) which is enough for this question.</p>
<p>If there is a better approach, please do comment it. Here is a link to my solution:- <a href="https://www.codechef.com/viewsolution/16367353">Click Here</a></p>
<p>If anyone did solve the second problem <a href="https://www.codechef.com/LTIME54/problems/LRQUER">L-R queries</a>, please explain me. Thanks.</p>raminiSun, 26 Nov 2017 00:33:35 +0530https://discuss.codechef.com/questions/118563/my-approach-for-smrstrnovember-lunchtime#programming#smrstr#codechefltime54