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 1220. Stacks

people, help!!!!!!!!!!!!!
Posted by alex kichkin 24 Oct 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!!!!!!!!!!!!!
Posted by Jew on the space 3 Jan 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!!!!!!!!!!!!!
Posted by morbidel 4 Jan 2012 15:10
Jew on the space wrote 3 January 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