Anyone who has solved problem E , please explain his approach .
the editorial says that first calculate cost for first level rows then do recalculation, but how to do it ? its quite unclear.
Upd:
What I thought is.. Suppose we have processed upto row no. x optimally and now processing x+1.
The calculation for the current row will not change the optimality of the row till x.
If we use this observation for the 1st row , We can optimally calculate the optimal cost to repaint the first row and make it in the form ABABAB....
Now... I got stuck from the 2nd row onwards..
What should we do to calculate the optimal cost for repainting from 2nd row to last row.
How should we process the column elements for a particular row ?
Upd 2:
Sol.`