C++ 'inline function' making TLE

Revision en1, by scopeInfinity, 2016-06-03 20:26:16

While I was submitting solution for http://www.codeforces.com/contest/86/problem/D, I was getting TLE.

So, I searched for getting faster inputs in C++. Somehow, It was Accepted. But, I didn't understand weird behavior of inline functions.

I think using inline functions make program runs faster, but in my case it was making TLE.

My Submissions with minor changes in 'readLongLong' function:

  • No Inline and Pass By Reference : Accepted

http://www.codeforces.com/contest/86/submission/18234613

  • Inline and Pass By Reference : TLE at test 42

http://www.codeforces.com/contest/86/submission/18234625

  • No Inline and value return : TLE at test 42

http://www.codeforces.com/contest/86/submission/18234694

  • Inline and value return : TLE at test 51

http://www.codeforces.com/contest/86/submission/18234684

Inline with Pass By Reference : TLE

inline void readLongLong (ll &val) {
	char ch;
	val = 0;
	while (true)
	{
		ch = getchar();
		if (ch < '0' || ch > '9') break;
		val = val*10 + (ch - '0');
	}
}

No Inline with Pass By Reference : Accepted

void readLongLong (ll &val) {
	char ch;
	val = 0;
	while (true)
	{
		ch = getchar();
		if (ch < '0' || ch > '9') break;
		val = val*10 + (ch - '0');
	}
}
Tags tle, inline, c++

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en1 English scopeInfinity 2016-06-03 20:26:16 1660 Initial revision (published)