I was thinking about what you pointed out to me, so I decided to change my code. Instead of relying in the map size to assign the “id” to each dirty cell I kept track in a separate variable. And got Accepted!
I guess the order of execution of the instructions in that statement is different in my machine and in SPOJ’s one?
Anyway, thank you so much for your help 