FPEvalRepoPublic/LeetCodeMetaData
0399
1{2 "id": 3470,3 "name": "maximum-score-from-grid-operations",4 "difficulty": "Hard",5 "link": "https://leetcode.com/problems/maximum-score-from-grid-operations/",6 "date": "2024-07-06",7 "task_description": "You are given a 2D matrix `grid` of size `n x n`. Initially, all cells of the grid are colored white. In one operation, you can select any cell of indices `(i, j)`, and color black all the cells of the `jth` column starting from the top row down to the `ith` row. The grid score is the sum of all `grid[i][j]` such that cell `(i, j)` is white and it has a horizontally adjacent black cell. Return the **maximum** score that can be achieved after some number of operations. **Example 1:** **Input:** grid = [[0,0,0,0,0],[0,0,3,0,0],[0,1,0,0,0],[5,0,0,3,0],[0,0,0,0,2]] **Output:** 11 **Explanation:** In the first operation, we color all cells in column 1 down to row 3, and in the second operation, we color all cells in column 4 down to the last row. The score of the resulting grid is `grid[3][0] + grid[1][2] + grid[3][3]` which is equal to 11. **Example 2:** **Input:** grid = [[10,9,0,0,15],[7,1,0,8,0],[5,20,0,11,0],[0,0,0,1,2],[8,12,1,10,3]] **Output:** 94 **Explanation:** We perform operations on 1, 2, and 3 down to rows 1, 4, and 0, respectively. The score of the resulting grid is `grid[0][0] + grid[1][0] + grid[2][1] + grid[4][1] + grid[1][3] + grid[2][3] + grid[3][3] + grid[4][3] + grid[0][4]` which is equal to 94. **Constraints:** `1 <= n == grid.length <= 100` `n == grid[i].length` `0 <= grid[i][j] <= 109`",8 "test_case": [9 {10 "label": "Example 1",11 "input": "grid = [[0,0,0,0,0],[0,0,3,0,0],[0,1,0,0,0],[5,0,0,3,0],[0,0,0,0,2]]",12 "output": "11 "13 },14 {15 "label": "Example 2",16 "input": "grid = [[10,9,0,0,15],[7,1,0,8,0],[5,20,0,11,0],[0,0,0,1,2],[8,12,1,10,3]]",17 "output": "94 "18 }19 ],20 "constraints": [21 "1 <= n == grid.length <= 100",22 "n == grid[i].length",23 "0 <= grid[i][j] <= 109"24 ],25 "python_template": "class Solution(object):\n def maximumScore(self, grid):\n \"\"\"\n :type grid: List[List[int]]\n :rtype: int\n \"\"\"\n ",26 "java_template": "class Solution {\n public long maximumScore(int[][] grid) {\n \n }\n}",27 "metadata": {28 "func_name": "maximumScore"29 }30}