题目是n个长方形,我用go写的,一开始超时后改用hash缓存后还超时,真一点没招了,牛友们有遇到相同情况吗这是我的代码:package mainimport "fmt"func niceput(rectangles [][]int, height int) int {var ans intfor _, rectangle := range rectangles {if rectangle[0] <= height && rectangle[1] <= height {ans += min(rectangle[0], rectangle[1])} else {if rectangle[0] > height {ans += rectangle[0]} else {ans += rectangle[1]}}}return ans}func min(a, b int) int {if a <= b {return a}return b}func main() {firstmap := make(map[int]map[int]int)var n, m intfmt.Scan(&n, &m)ans := 0for i := 0; i < n; i++ {recs := [][]int{}var x, y intfmt.Scan(&x, &y)if x < y {x, y = y, x}//如果map中有结果,直接调用,不用再计算一次if v, ok := firstmap[x][y]; ok {ans += vcontinue}recs = append(recs, []int{x, y})curput := niceput(recs, m)ans += curputif _, ok := firstmap[x]; !ok {firstmap[x] = make(map[int]int)}firstmap[x][y] = curput//把结果记录在map中}fmt.Println(ans)}