Your question is incorrect without code. In C++ 11, there are a lot of new features.
Maybe just performance improvement of C++11 over earlier versions gives you AC.
Look for example for string class. In C++98, strings are much slower, than modern strings.
Your AC code runs in 800ms. Mine just in 240.
http://acm.timus.ru/status.aspx?space=1&num=1613&author=201928You can made a lot of optimizations.
After those optimizations, you will get no TLE on G++4.9.