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

The problem say that "It is guaranteed that during the experiment each time a coin was to be removed the stack was not empty."
But when I submit such a brute force code:
--------------------
        if (x > 0) a[t++] = x;
        else if (x == 0) {
            if (t + t < maxn) {
                copy(a, a + t, a + t);
                t += t;
            }
        }
        else printf("%d\n", a[--t]);
--------------------
It crashed at #42. Then, I modified the last "else branch" into:
--------------------
        else if (t) printf("%d\n", a[--t]);
--------------------
I got WA at #42.
What if t = maxn/2 + 1 and than t + 1 pop operations?
For example:
1000000
1
0
0
..
0 (20 times)
-1
-1
..
-1 (1000000 - 21 times)

You will store only 2^19 copies in array, and get crash
Oh..Sorry..It's my fault.
I only set the size of a to 1000001 * 2, but I forgot to modify the maxn....
I apologize for asking so stupid question.T_T
Accepted now, thank you very much.
Yeah,I've made the same mistake,and thank you so much!