what are the optimisation approaches which one can use to get rid of ‘time limit exceeded’ problem during submitting code?
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
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…
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
YOU CAN LEARN ALOT FROM HERE : https://www.coursera.org/course/optimization
thank you kunal but without constraints this code is working
…<?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($i<strlen($s))
{
if($s[$i]===’<’)
{
$x+=2;
}
else if($x>0)
{
$right+=2;
if($right==$x){$pars +=$right;$x=0;$right=0;}
}
else
{
break;
}
$i++;
}
return $pars;
}
?>
I am dealing with the same problem.
sorry processor capacity
actually u r wrong…we indeed need to understand the constraints!!!
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!!!
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 TSORT Problem - CodeChef …just try it!!!
this is ur corrected code…CodeChef: Practical coding for everyone can u guess what was eating up the time???
you are really helpful thanks for catching error in my script
$len=strlen($s);
for($i=0;$i<$len;$i++)