N. Mixed Dimensions

Codeforces
IDCF10098N
Time1000ms
Memory256MB
Difficulty
English · Original
Formal · Original
Mixed Dimensions is an innovative company that is specialized in 3D printing technologies. They are planning to 3D print decorative tiles to be used in the beautiful pavements of Amman. After printing thousands of these decorative tiles, Mixed Dimensions washed the tiles with water to make them look fresh before they are delivered. Unfortunately, water gathered inside some places in the decorations. Observing the problem, they decided to fill any cavity (hole) in the decorations so that no water gathers after a rainy day. Given a 3D printed tile that represents a grid of size R×C, and the height in unit cubes above each point in the grid, your task is to compute the volume of printing material needed to fill the cavities (holes). Two units3 of printing material are needed to fill this tile. The first line of input contains two integers R and C (1 ≤ R, C ≤ 500), the number of rows and columns of the base grid, respectively. Each of the following R lines contains C integers, each integer is between 1 and 109 and represents the height in unit cubes above one of the cells. Print the volume of the printing material needed to fill the given tile so that no water gathers after a rainy day. ## Input The first line of input contains two integers R and C (1 ≤ R, C ≤ 500), the number of rows and columns of the base grid, respectively.Each of the following R lines contains C integers, each integer is between 1 and 109 and represents the height in unit cubes above one of the cells. ## Output Print the volume of the printing material needed to fill the given tile so that no water gathers after a rainy day. [samples]
**Definitions** Let $ R, C \in \mathbb{Z} $ be the dimensions of the grid, with $ 1 \leq R, C \leq 500 $. Let $ H = (h_{i,j})_{R \times C} $ be a matrix of integers, where $ h_{i,j} \in [1, 10^9] $ represents the height of the grid cell at row $ i $, column $ j $. **Constraints** 1. $ 1 \leq R, C \leq 500 $ 2. $ 1 \leq h_{i,j} \leq 10^9 $ for all $ i \in \{1, \dots, R\}, j \in \{1, \dots, C\} $ **Objective** Compute the total volume of material needed to fill all cavities such that no water can be retained after rainfall, assuming water flows to the boundary if possible. This is equivalent to computing the difference between the volume of the "filled" terrain (where every cell is filled up to the minimum height of the boundary path that connects it to the edge) and the original terrain. Let $ f(i,j) $ be the maximum water level that can be sustained at cell $ (i,j) $ without spilling to the boundary — i.e., the minimum of the maximum heights along all paths from $ (i,j) $ to the grid boundary. Then: $$ f(i,j) = \min_{\text{path } P \text{ from } (i,j) \text{ to boundary}} \left( \max_{(x,y) \in P} h_{x,y} \right) $$ The volume of material needed is: $$ V = \sum_{i=1}^{R} \sum_{j=1}^{C} \max(0, f(i,j) - h_{i,j}) $$
API Response (JSON)
{
  "problem": {
    "name": "N. Mixed Dimensions",
    "description": {
      "content": "Mixed Dimensions is an innovative company that is specialized in 3D printing technologies. They are planning to 3D print decorative tiles to be used in the beautiful pavements of Amman. After printin",
      "description_type": "Markdown"
    },
    "platform": "Codeforces",
    "limit": {
      "time_limit": 1000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "CF10098N"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "Mixed Dimensions is an innovative company that is specialized in 3D printing technologies. They are planning to 3D print decorative tiles to be used in the beautiful pavements of Amman.\n\nAfter printin...",
      "is_translate": false,
      "language": "English"
    },
    {
      "statement_type": "Markdown",
      "content": "**Definitions**  \nLet $ R, C \\in \\mathbb{Z} $ be the dimensions of the grid, with $ 1 \\leq R, C \\leq 500 $.  \nLet $ H = (h_{i,j})_{R \\times C} $ be a matrix of integers, where $ h_{i,j} \\in [1, 10^9] ...",
      "is_translate": false,
      "language": "Formal"
    }
  ]
}
Full JSON Raw Segments