vibrant1's blog

By vibrant1, history, 9 days ago, In English,

https://codeforces.com/contest/7/problem/B In this problem i am not getting meaning of Defragment so please can anyone explain in some different way with one test case so that i can understand ?

 
 
 
 
  • Vote: I like it
  • 0
  • Vote: I do not like it

»
9 days ago, # |
  Vote: I like it 0 Vote: I do not like it

Suppose you have a memory block as 0000 0000 0000 0000. if you do (alloc 2)(and considering that number will not exceed 4 bytes) operation, what is going to happen is this: You take first 4 bytes and it is going to look like this (0010) 0000 0000 0000. if you have another operation like this, say (alloc 3), you are going to take second 4 bytes and it becomes like this (0010)(0011)00000000 And next operation is (erase 2), we should erase 2 from memory, memory block looks like this 0000 (0011) 0000 0000. So the main part: if you do defragment operation, you should bring all the blocks as close to the beginning of the memory as possible and preserving their respective order as said in the statement, so block looks like this: (0011) 0000 0000 0000

P.S: Here alloc is not the same as in the statement, but anyway the thing is to understand defragment