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

Обсуждение задачи 1220. Stacks

people, help!!!!!!!!!!!!!
Послано alex kichkin 24 окт 2011 00:43
I always get WA#10 here is my solution

#include <iostream>
#include <vector>
#include <string>
#include <stack>
using namespace std;

int main(){
#ifndef ONLINE_JUDGE
    freopen("input.txt","rt",stdin);
    freopen("output.txt","wt",stdout);
#endif
    string operation;
    stack <long > znach[1002];

    short n;
    short int x;
    long  y;
    cin >>n;

    for (short i=1; i<=n; i++){

        cin >> operation;

        if(operation=="PUSH"){
            cin >> x;
            cin>>y;
            znach[x].push(y);
        }else{


            cin >>x;
            long z=znach[x].top();
            cout <<z<<endl;
            znach[x].pop();
    }

}
}
one who finds a mistake, please write back
Re: people, help!!!!!!!!!!!!!
Послано Jew on the space 3 янв 2012 21:20
are you crazy, man? It's not too easy problem as you think.You should write your OWN stack
Re: people, help!!!!!!!!!!!!!
Послано morbidel 4 янв 2012 15:10
Jew on the space писал(a) 3 января 2012 21:20
are you crazy, man? It's not too easy problem as you think.You should write your OWN stack
@Jew on the space
Hey, please be more respectful. He complains about receiving WA not MLE so he has a point.
@alex kichkin
The problem in your code is that you declared i and n as shorts (which is 2 bytes) but n can be at most 100000 (so 4 bytes is needed). Changing your code with int type for i and n gives correct MLE now. Further on, as Jew on the space suggested, you should develop yourself a stack, more suitable with the problem constraints.
Cheers