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

Общий форум

1220 - stacks
Послано hemmul 30 окт 2004 19:35
i have made several approaches to this problem, and just can't figure out where the trick is:
step 1:
i used std::stack<long int> to handle stacks and std::vector<long int> to store the output (ok, it's not necessary to store the output (just output the numbers as the are poped out), but it is not principal in this case)
the result is - memory limit error...
step 2:
after noticing that sizeof(std::stack<long int>)=40 (!) i decided to make my own stack. for this purpose i used the linked list, and each time i was travelling from the head to the tail, and inserting the new element to the back. but surely it was slow, and the time limit was violated on test N10. after that i changed the list so, that the new element is inserted to the front of the list (rearranging the necessary pointers), and i don't need to travel the whole structure from front to back in order to find the upper-most element.
That is, the final version of my stack is:
struct node
{
// member functions: push(), pop()...
node* pNest;
long int number;
}

this means, that the sizeof(node)=8. but taking into the account that 100000 stack operations are to be awaited, and in the worst case all of them are "PUSH" - i'l allocate 8*100000 ~ 800 KB, that is more than 750 KB of memory limit...
i just can't think of any other structure of the stack, besides the linked list of the kind above. can anyone give me some hint?
thanks everyone who read this message so far even till this line :)