ENG  RUSTimus Online Judge
Online Judge
Задачи
Авторы
Соревнования
О системе
Часто задаваемые вопросы
Новости сайта
Форум
Ссылки
Архив задач
Отправить на проверку
Состояние проверки
Руководство
Регистрация
Исправить данные
Рейтинг авторов
Текущее соревнование
Расписание
Прошедшие соревнования
Правила
вернуться в форум

Обсуждение задачи 2011. Длинное условие

scala too slow?
Послано Vassili Skarine 31 мар 2014 08:21
tried tons of optimizations but Scala solution still TLE, any suggestions?
Re: scala too slow?
Послано Vassili Skarine 31 мар 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?
Послано akos tajti 17 июн 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.