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 2011. Long Statement

scala too slow?
Posted by Vassili Skarine 31 Mar 2014 08:21
tried tons of optimizations but Scala solution still TLE, any suggestions?
Re: scala too slow?
Posted by Vassili Skarine 31 Mar 2014 08:45
ok so I got AC
the key difference seems to be in using correct way to read the input
if I use readLine().split(' ').map(_.toInt) then it always TLE
but if I read input using Java Scanner:
  val sc = new Scanner(System.in);
  .... sc.nextInt() ...
then it works fine

Edited by author 31.03.2014 08:45
Re: scala too slow?
Posted by akos tajti 17 Jun 2014 14:20
I also have many problems with scala. My scala code runs two times slow than the corresponding java code. Sometimes it's really hard to optimize. My tips (in general, not specifically about this problem):
* don't use vars if not really necessary
* foldLeft and similar functions are slow unfortunately (although I tend to use them anyways, only switch to for when I got a TLE)
* array initialization is REALLY slow especially if you use fill (much more slower than java). try to keep your arrays as small as possible. For example sometimes it's possible to keep only the last two rows of a matrix.