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 1806. Mobile Telegraphs

Java
Posted by Moonstone [Samara SAU] 1 Nov 2010 01:57
Is it possible to solve it in Java without any special tricks?
I got MLE #16 any time when I submitted it in Java. Of course, the same C++ code gets AC and uses 35 MB.

I think that it is not good when equal solutions get different verdicts. Am I right? Admins, maybe you should increase memory limit?

Edited by author 01.11.2010 10:11
Re: Java
Posted by Warlock 1 Nov 2010 15:39
Maybe you have problem with huge amount of strings while construct graph. std::string is mutable, but java.lang.String is immutable and you not call garbage collector for removing unnecessary copies. Java solution without strings require only 12MB http://acm.timus.ru/status.aspx?space=1&num=1806&author=38899
Re: Java
Posted by Moonstone [Samara SAU] 1 Nov 2010 22:55
I used strings only for reading input (not too much memory), then I used arrays of byte to store numbers and longs to keep them in map.

Your 12 MB solution is too perfect :) Many other C++ solutions use about 40 MB and, rewritten in Java, they will be MLE. It means that C++ and Java are not equal in their opportunities for this problem. I don't like this. And you?

By the way, Saratov provides programmers 256 MB for each problem. Why Timus can not do the same?
Re: Java
Posted by KALO 6 Nov 2010 23:01
Do not create the whole graph forward, just get the neighbours for the current vertex which is already removed from heap, this is the only trick :). I've got AC with standard java HashMap and PriorityQueue.
Re: Java
Posted by Ibragim Atadjanov (Tashkent U of IT) 7 Nov 2010 06:17
wont it give tl if each step you go through 50000 neighbours.
About n*n/2 in worth case
Re: Java
Posted by Sergey Lazarev (MSU Tashkent) 7 Nov 2010 11:00
Each vertex has at most 135 neighbours.
Re: Java
Posted by Ibragim Atadjanov (Tashkent U of IT) 9 Nov 2010 02:14
ur right accepted. Thanks.
Thanks to KALO too for the help.