rows + 2 horizontal and cols + 2 vertical ones, splitting it into 1 × 1 cells. Horizontal bars are numbered top to bottom from 1 to rows + 2, vertical bars left to right from 1 to cols + 2.
Some bars can be pulled out: the horizontal bars listed in loose_rows and the vertical bars listed in loose_cols. All other bars are fixed in place.
Remove any of the loose bars (possibly none) so that a square opening appears in the lattice, and return the largest possible area of such an opening.rows=4, cols=3, loose_rows=[2, 3, 4], loose_cols=[3, 4] → 9
Removing horizontal bars 2–4 opens a gap 4 cells tall; removing vertical bars 3 and 4 opens one 3 cells wide. The square is limited by the smaller side: 3 × 3 = 9.
rows=5, cols=5, loose_rows=[2, 4, 6], loose_cols=[2, 3] → 4
No two removable horizontal bars are adjacent, so the gap can be at most 2 cells tall. The answer is 2 × 2 = 4.
rows, cols ≤ 10⁹len(loose_rows), len(loose_cols) ≤ 10⁴loose_rows[i] ≤ rows + 1loose_cols[i] ≤ cols + 1rows=4, cols=3, loose_rows=[2, 3, 4], loose_cols=[3, 4]
9
Run checks the first 3 tests in your browser. Submit checks all 93 tests on the server, hidden ones included.