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

Обсуждение задачи 1650. Миллиардеры

I've got TLE with heap
Послано Mr.Arsalan 22 янв 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
Послано Vedernikoff Sergey (HSE: EconomicsForever!) 22 янв 2009 17:15
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
Послано Mr.Arsalan 22 янв 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
Послано svr 22 янв 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
Послано Mr.Arsalan 22 янв 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
Послано Mr.Arsalan 24 янв 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
Послано ValenKof 18 дек 2011 05:10
I used maps, set, vectors, cin & cout and my program works 0.875. There is no need in scanf().