Back to Blogs
USACOCompetitive ProgrammingGridsSimulationJune 3, 2026

USACO 2025 Reflection: Symmetry Groups and Grid Updates

A grid-symmetry lesson for USACO students: group reflected cells, compute the cost per group, and update carefully after toggles.

Reflection is a grid problem where the hard part is not reading the grid. The hard part is realizing that cells belong to reflection groups. Each group must eventually agree on one character.

Think in groups of four

In a square grid with horizontal and vertical reflection, a cell is connected to up to three reflected partners. For a typical group of four cells, the cheapest fix is:

min(number of '#', number of '.')

If a group has three # cells and one ., changing the one dot is cheaper. If it has two and two, either target costs two changes.

Add group costs

The total answer is the sum of the cheapest cost for every reflection group.

Group cellsMake all #Make all .Cost
# . # .2 changes2 changes2
# # # .1 change3 changes1

Handling updates

A simple implementation can recalculate all group costs after each toggle. A faster implementation subtracts the old cost of the affected group, toggles the cell, then adds the new cost of that same group. Either way, the concept is the same: only group agreement matters.

Common mistakes

  • Counting each reflection group more than once.
  • Reflecting row coordinates correctly but not column coordinates.
  • Updating the grid cell before saving the old group cost in an optimized version.
  • Assuming every group always has four distinct cells without checking grid size assumptions.

Practice prompt

Draw a 4 by 4 grid and mark the four cells connected to position (0, 2). Fill them with two # and two ., then decide the minimum number of changes.