This problem requires good memory manipulation. Can anyone help me please ?
Note : Memory Limit is 0.75 MB
Here is Link
# | User | Rating |
---|---|---|
1 | tourist | 3993 |
2 | jiangly | 3743 |
3 | orzdevinwang | 3707 |
4 | Radewoosh | 3627 |
5 | jqdai0815 | 3620 |
6 | Benq | 3564 |
7 | Kevin114514 | 3443 |
8 | ksun48 | 3434 |
9 | Rewinding | 3397 |
10 | Um_nik | 3396 |
# | User | Contrib. |
---|---|---|
1 | cry | 167 |
2 | Um_nik | 163 |
3 | maomao90 | 162 |
3 | atcoder_official | 162 |
5 | adamant | 159 |
6 | -is-this-fft- | 158 |
7 | awoo | 155 |
8 | TheScrasse | 154 |
9 | Dominater069 | 153 |
10 | djm03178 | 152 |
This problem requires good memory manipulation. Can anyone help me please ?
Note : Memory Limit is 0.75 MB
Here is Link
Name |
---|
Comment deleted
LOL WUT
I solved it using handmade linked lists. Use arrays values, last, prev. All numbers are stored in array values, one after another. last[s] is the index of the last value of the s-th stack (and values[last[s]] is the value itself). And prev[i] is the index of the element before element with index i (their values are values[prev[i]] and values[i] correspondingly).
It requires one small array (last, of length about 1000) and two big arrays (values, prev, of length about 100000). So the memory usage will be 100000 * 4 * 2 = 0.8 MB, and it doesn't fit. But all elements of array prev have values no more than 2^17. So we can consider that the first 17 bits of the array prev store prev[0], the second 17 bits store prev[1] and so on — about 0.2 MB instead of 0.4. It passes.
I wonder how you are going to use ( manipulate ) this 17 bits ? Could you please be more clear ? Sorry for my bad english ?
My solution takes 0.171s and 540 KB and is as follows:
We know that there are at most 100,000 operations and it's guaranteed that all operations will be valid. In the worst case the operations would be PUSH A B, where A is the same for all operations. In the average case the sum of elements in all stacks will be at most 100,000, so we only need a container of 100,000 elements, lets call it S.
Now the problem is to find the initial position of each stack A in S, let top[i] be the top position of stack i. I have processed all the instructions to find the maximum height of each stack and then:
where maxi() is the index of the tallest stack and maxh() is the height of that tallest stack, drop the last stack of the rest and repeat the steps for all stacks(1000). maxi() and maxh() are only theoretical functions but I have used an array pos[1000][2] to store the index->max_heigth and, then I have sorted in non increasing order.
To process all the instructions, would be necessary to store all the instructions, and then use it in the simulation and later in the real task, however, we have little memory, and since in the worst case we'll need to store 200,000(~800kb) elements this isn't an option. My solution was to read all the input and then rewind the stdin and read the input again to do the real task.
PUSH:
POP:
Try this and if after this you need the code I'll post it here too.
EDIT: The code
I have tried some optimization to reduce memory but the saving is only 14 KB.
Wow I saw you first on rank-list of this problem. And I wish I could understand you :D :: How to rewind stdin ?
Really? I am in the place 907.
Well, in C/C++ I use the rewind() function, I don't know how to do the same in other languages but it shouldn't be that hard.
can you post code?
O RLY?
doya know what that means?