reducing execution time of program

what are the optimisation approaches which one can use to get rid of ‘time limit exceeded’ problem during submitting code?

I am dealing with the same problem.

To get rid of TLE, you need to understand the constraints of that particular problem, then only start with coding.

Costraints tell us about codechef compiler capacity…i think we do not need to discus about constraints

sorry processor capacity

actually u r wrong…we indeed need to understand the constraints!!!

<?php $t=fgets(STDIN); $limit=array(); if($t<=500) { for($x1=0;$x1<$t;$x1++) { if(count($limit)<=5000000) { $s=trim(fgets(STDIN)); $limit[]=$s; } if(strlen($s)<=1000000) { echo shailesh($s)."\n"; } } } function shailesh($s) { $right=0; $x=0; $pars=0; for($i=0;$i0) { $right+=2; if($right==$x){$pars +=$right;$x=0;$right=0;} } else { break; } } return $pars; } ?>

this code showing time exceed problem according you…it’s follow constraints or pressure

tell me mistr kunal

u dont get it…constraints help u manipulate ur algorithm!!!

i’ll give u a sum…see how the constraints help…

generally on CodeChef, when you are getting TLE, it means that your algorithm is not correct and you need to work in that direction.
But ya few times, optimization techniques are required.
Just for example, if you use c++, then prefer scanf and printf over cin and cout, will be quicker.

And many more techniques like this… :slight_smile:
Rest as no ongoing contest is going on, you can share the code in which you found such problems. I would be glad to help


1 Like

if u want i can give u many more such examples…one more…which is one of the easiest sums…where constraints help u reduce time is …just try it!!! check this problem and tell me what’s wrong with my cod please

this is ur corrected code… can u guess what was eating up the time???

thank you kunal but without constraints this code is working
echo shailesh($s)."\n";

function shailesh($s)
else if($x>0)
if($right==$x){$pars +=$right;$x=0;$right=0;}
return $pars;



<?php fscanf(STDIN,"%d\n",$t); for($x1=0;$x1<$t;$x1++) { fscanf(STDIN,"%s\n",$s); echo shailesh($s)."\n"; } function shailesh($s) { $right=0; $x=0; $pars=0; $i=0; while($i0) { $right+=2; if($right==$x){$pars +=$right;$x=0;$right=0;} } else { break; } $i++; } return $pars; } ?>

you are really helpful thanks for catching error in my script

that is not what @vikascingh and i are trying to convey…!!!