haechandev
Algorithms

[Baekjoon 17135] Castle Defense

Enumerate archer placements and simulate each game independently.

August 23, 2022

Once the positions of three archers are chosen, the rest of the game is determined. I enumerated combinations of three columns, copied the original map for each placement, and simulated one turn at a time.

Each archer targets the nearest enemy within range, choosing the leftmost enemy when distances tie. The implementation checks distance and columns from left to right to enforce that priority. Several archers can choose the same enemy, so I separately marked enemies already handled in the turn to avoid counting duplicates.

The small number of possible placements let me separate placement combinations from game simulation.

Problem: Baekjoon · Code: View on GitHub