Skip to main content

Posts

Iron, Magnet and Wall Codechef November Long challenge 2020 solution with code explanation

 Iron, Magnet and Wall  Codechef November Long challenge 2020 solution with code explanation - Iron, Magnet and Wall  Codechef November Long challenge 2020 solution with code explanation  Let's read problem statement, Chef loves to play with iron (Fe) and magnets (Ma). He took a row of  N N  cells (numbered  1 1  through  N N ) and placed some objects in some of these cells. You are given a string  S S  with length  N N  describing them; for each valid  i i , the  i i -th character of  S S  is one of the following: 'I' if the  i i -th cell contains a piece of iron 'M' if the  i i -th cell contains a magnet '_' if the  i i -th cell is empty ':' if the  i i -th cell contains a conducting sheet 'X' if the  i i -th cell is blocked If there is a magnet in a cell  i i  and iron in a cell  j j , the  attraction power  between these cells is  P i , j = K + 1 − | j − i | − S i , j P i , j = K + 1 − | j − i | − S i , j , where  S i , j S i , j  is the