Comments

Start from the losing condition and think about how each player can prevent that from happening. Alice loses when no red cells remain and Bob loses when no blue cells remain. Therefore, Alice should minimize loss of red cells and maximize loss of blue cells.

Now think about each of the possible moves. Alice can only play WR/RW, BR/RB, or RR as she must include at lease one red cell. BR/RB is strictly better than WR/RW because both reduce red cells by 1 while BR/RB also reduces blue cells by 1. RR is even worse as it reduces red cells by 2 without affecting blue cells.

Therefore, BR/RB is the best move for Alice (and the same logic applies to Bob).

+4

Your second last for loop misses the final element (the condition should be i < n). It gets AC after fixing this.