Hi,
I'm trying to learn Scala and thought that using SPOJ as a source of 'practical' examples could be helpful.
I must say, I'm a bit disappointed. Surely, we are not trying to establish which language generates the least memory footprint or where we can create faster code (obviously it's going to be assembler).
I'm getting similar results (i.e. min. memory consumption is 207M and ridiculous execution time, often leading to TLE).
I did some checking and managed to optimise my IO a fair bit. Just so you know (perhaps it could be useful to other Scala SPOJers):
[ul]
[li]readInt() performs resonably good (on my PC I was able to read 500k lines and parse them as ints in 130ms)[/li]
[li]most problems are caused by println: printing the same 500k lines took about 4.5s. However, if you do
the time drops to about 180ms[/li][/ul]
All in all I managed to read 500k ints and write them back in about 280ms, which isn't bad. The same in C takes about 130ms, so I think 300ms is 'good enough' for Scala.
Alas! I still get TLE.
I started investigating further by cutting out the functionalities of my code. It turns out that:
- just reading and writing took 1.66s (this obviously generated 'wrong answer', but I did it just to check how bit an overhead I/O is)
- writing loop counter took 1.41s
- only reading data took 1.24s
I removed everything (just empty main()) and it still takes 1s and still consumes 207M. Probably, the mem is just 'normal' jvm footprint, but 1s for starting app which does nothing seems to indicate some kind of a problem...
I have the following suggestions:
- please increase both mem and time for jvm languages. If empty main() takes 1s and consumes over 200M, I don't see how to avoid exceeding mem or time for some of the problems. Better yet, just subtract the 1s and 200M --- this seems to be baseline consumed by the jvm itself
- add some scaling factor... obviously, the speed of languages isn't equal... it should be fairly easy to estimate... based on the existing results if nothing else
I think the tasks, where IO time has such high impact on the result aren't really well defined. Surely, it is possible to increase the complexity instead of the volume of data. Say, instead of processing 10 times more data, just multiply them by 10. This would test the algorithm much better.