ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1126. Magnetic Storms

Don't use minmax.h
Posted by Artyom Averin [Psych Up club] 17 Mar 2012 13:30
<minmax.h> -> TLE2
<algorithm> -> AC 0.046 :-)
Re: Don't use minmax.h
Posted by Vladimir Yakovlev (USU) 18 Mar 2012 08:02
<minmax.h>
#define max(a,b)            (((a) > (b)) ? (a) : (b))
#define min(a,b)            (((a) < (b)) ? (a) : (b))

<algorithm>
template<class T> inline const T& (max)(const T& a, const T& b) {return (b < a ? a : b);}
template<class T> inline const T& (min)(const T& a, const T& b) {return (b < a ? b : a);}

So, with <minmax.h> if you write
int rec(x){
  ...
  return max( rec(y), rec(z) );
}
you call rec(y) and rec(z) twice because last line of code is preprocessed to
return rec(y) > rec(z) ? rec(y) : rec(z);


Edited by author 18.03.2012 08:04