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 1650. Billionaires

I've got TLE with heap
Posted by Mr.Arsalan 22 Jan 2009 17:07
It seems that the time limit for this problem is so tight, because I used heap + set and map and I got TLE. Does anybody have any suggestions?

Edited by author 22.01.2009 17:08
Re: I've got TLE with heap
I've used almost the same structures and AC. Try to optimize your program. Do you use scanf()/printf() for input/output?
Re: I've got TLE with heap
Posted by Mr.Arsalan 22 Jan 2009 19:10
Thank for your Reply.
Yeah, I used scanf/printf for IO. I think I should have reduce the number of maps in my code. I used following structures:
map < string , int > city_to_index ;// locate the position of each city in the heap.
map < string , string > where;// locate the city in where the billionaire is
map < string , LL > how_much;// the amount of money each billionaire has
map < string , int > answer;// the answers
Do you have any idea to reduce them?
One problem that I think that my cause TLE is that I built my heap in array and each time I update my heap I should have change the values in city_to_index. Maybe if I implement it with pointers would be better. I mean, it may be better to build the heap with pointers and for swapping the nodes their addresses in city_to_index remains unchanged. (map<string,node*> city_to_index) IT IS SOMEHOW COMPLICATED FOR ME TO IMPLEMENT IN THAT WAY, DO YOU HAVE ANOTHER IDEA?

Edited by author 22.01.2009 19:23
Re: I've got TLE with heap
Posted by svr 22 Jan 2009 19:23
You must before coding be sure in time and
space limits of your algo. This is difficult but
is core of programming skills.
You take right general plan remove bags and get AC.
Re: I've got TLE with heap
Posted by Mr.Arsalan 22 Jan 2009 19:31
Thanks for your advice. I had though about them before implementing my solution. and I think my running time except the part dealing with maps is O(lg n) per line of input and it is perfectly OK, and that's why I asked in forum about how to get rid of TLE.

Edited by author 22.01.2009 19:36
Re: I've got TLE with heap
Posted by Mr.Arsalan 24 Jan 2009 00:33
I've reduce the number of maps in my solution and now it gives WA on test #10. Is there any tricky test cases?
Re: I've got TLE with heap
Posted by ValenKof 18 Dec 2011 05:10
I used maps, set, vectors, cin & cout and my program works 0.875. There is no need in scanf().