Пожалуйста, прочтите новое правило об ограничении использования AI-инструментов. ×

C++ 'inline function' making TLE

Правка en1, от 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');
	}
}
Теги tle, inline, c++

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en1 Английский scopeInfinity 2016-06-03 20:26:16 1660 Initial revision (published)