|
|
back to boardMemory limit exceeded? Why? #include <iostream> #include <vector> #include <string> #include <stack> #include <map> int main() { int N; std::string str; while(std::cin >>N) { std::vector<std::stack<int> > stacks; std::map <int,int> MapS; int count=0; for(int i=0;i<N;i++) { std::cin >>str; if(str=="PUSH") { int a,b,ind; std::cin >>a>>b; if(MapS.find(a)!=MapS.end()) { ind = MapS[a]; } else { std::pair<int,int> x; x.first = a; x.second = count++; MapS.insert(x); ind = x.second; stacks.push_back( std::stack<int>() ); } stacks[ind].push(b); } else if(str == "POP") { int a,ind; std::cin >>a; if(MapS.find(a)!=MapS.end()) { ind = MapS[a]; } std::cout <<stacks[ind].top()<<std::endl; stacks[ind].pop(); } } } return 0; } |
|
|