haechandev
Algorithms

[Baekjoon 1028] Diamond Mine

A Platinum DP solution that expands smaller diamonds and checks all four edges.

August 27, 2022

The task is to find the largest diamond outline in a grid of zeros and ones. I increased candidate sizes from one, extending only positions where the upper portion of the previous size had worked.

A larger diamond needs both upper edges and both lower edges to consist of ones. For each candidate vertex, I checked the diagonal boundaries directly and updated the maximum when all four edges passed.

Rather than inspect every vertex and every size from scratch, I extended only positions with dp[y][x] == size - 1. Trying larger diamonds only where a smaller one had already worked was the central idea of this implementation.

Problem: Baekjoon · Code: View on GitHub