+ 1
This code is throwing 'the time limit exceeded' error, please check the code .
The problem is given in the link below I was expecting the result but a time limit related error is being shown . https://www.hackerrank.com/contests/university-codesprint-3/challenges/erupting-volcanoes https://code.sololearn.com/cvCrpou0p6tv/?ref=app
6 Answers
+ 19
https://www.sololearn.com/discuss/456645/?ref=app
https://www.sololearn.com/discuss/397287/?ref=app
https://www.sololearn.com/discuss/201138/?ref=app
https://www.sololearn.com/discuss/78223/?ref=app
+ 5
In addition to what has been stated. It looks like you could just set the size of the array based off of n by n instead of using 400 by 400. Then there should be no need to initialize the array to all zeros, but rather just set the actual values. Besides your first nested array has an infinite loop as it is right now. The condition is set to f = 400 instead of f <= 400. Organizing your code better would help you to see these types of mistakes. There are other issues as well, but you should attempt to clean up your code before I'll jump into that.
+ 2
I did not go through your compete code, but one suggestion that may solve your problem is
rather than using for loops to initialize your array, better approach would be to use memset method under cstring header.
like
memset (d,0,sizeof(d));//saves resources and time
Hope this helps.
+ 2
I don't know about it much, will try it , thanks
+ 2
@ChaoticDawg thanks , I am looking again it .
+ 2
@ChaoticDawg I set all array to zero so that I do not get any garbage when I need to add values to it .