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 1915. Titan Ruins: Reconstruction of Bygones

Guys, I accpeted but really cheated.... :-))
Posted by Sanatbek_Matlatipov 13 Sep 2015 21:12
I used Java: The following I did.
1. Declare Stack<Integer>.
like this:         Stack<Integer> st = new Stack<Integer>();
                   boolean ok = false; <--// this boolean is tricky.. :))
2. Then, I iterate from 1 to n init i read X and i checked three given if statements in input. They are:
1.if(x>0){st.push(x);}
2.if(x==-1){pw.println(st.pop());}
3.if(x==0){
       int len = st.size();
       if(2*len<=n){
                st.addAll((Collection) st.clone());
    } else{
           if(!ok){
// here If you don't use this if statement you will have Memory Limit #42...
                      st.addAll((Collection<? extends Integer>) st.clone());
             ok=true;
            }
    }
}
Problem is copying all stack elements...
What I am really doing here is using stack clone() method. But When you do so many clones will have MemLimit. That's why I checked that my Stack size and its copies are more than N (2*len>n) then I should copy the whole stack one time not more.
And I am thinking that above code worked because <b<stack size wansn't big enough when I cloned last time....

Sorry If I am mistaken and poor english. But this code AC ...