add new solutions

This commit is contained in:
kanna5 2026-01-05 16:48:03 +09:00
parent d798d5e8c9
commit 886b5e0a8e
Signed by: kkyy
GPG key ID: 06332F3965E9B0CF
34 changed files with 1164 additions and 0 deletions

View file

@ -0,0 +1,42 @@
package q3047
import "slices"
func intersectingSquareArea(bl1, tr1, bl2, tr2 []int) int64 {
l1, r1, l2, r2 := bl1[0], tr1[0], bl2[0], tr2[0]
iW := max(0, min(r1, r2)-max(l1, l2))
l1, r1, l2, r2 = bl1[1], tr1[1], bl2[1], tr2[1]
iH := max(0, min(r1, r2)-max(l1, l2))
edge := min(iW, iH)
return int64(edge * edge)
}
func largestSquareArea(bottomLeft [][]int, topRight [][]int) int64 {
squares := make([]int, len(bottomLeft))
for i := range squares {
squares[i] = i
}
slices.SortFunc(squares, // bottom-up order
func(a, b int) int { return bottomLeft[a][1] - bottomLeft[b][1] })
var largest int64
for i := range squares {
for j := i + 1; j < len(squares); j++ {
yI, yJ := topRight[squares[i]][1], bottomLeft[squares[j]][1]
if yJ >= yI {
break
}
largest = max(largest, intersectingSquareArea(
bottomLeft[squares[i]], topRight[squares[i]],
bottomLeft[squares[j]], topRight[squares[j]],
))
}
}
return largest
}
var _ = largestSquareArea