E. Fire in the City

Codeforces
IDCF845E
Time2000ms
Memory256MB
Difficulty
binary searchdata structures
English · Original
Chinese · Translation
Formal · Original
The capital of Berland looks like a rectangle of size _n_ × _m_ of the square blocks of same size. Fire! It is known that _k_ + 1 blocks got caught on fire (_k_ + 1 ≤ _n_·_m_). Those blocks are centers of ignition. Moreover positions of _k_ of these centers are known and one of these stays unknown. All _k_ + 1 positions are distinct. The fire goes the following way: during the zero minute of fire only these _k_ + 1 centers of ignition are burning. Every next minute the fire goes to all neighbouring blocks to the one which is burning. You can consider blocks to burn for so long that this time exceeds the time taken in the problem. The neighbouring blocks are those that touch the current block by a side or by a corner. Berland Fire Deparment wants to estimate the minimal time it takes the fire to lighten up the whole city. Remember that the positions of _k_ blocks (centers of ignition) are known and (_k_ + 1)-th can be positioned in any other block. Help Berland Fire Department to estimate the minimal time it takes the fire to lighten up the whole city. ## Input The first line contains three integers _n_, _m_ and _k_ (1 ≤ _n_, _m_ ≤ 109, 1 ≤ _k_ ≤ 500). Each of the next _k_ lines contain two integers _x__i_ and _y__i_ (1 ≤ _x__i_ ≤ _n_, 1 ≤ _y__i_ ≤ _m_) — coordinates of the _i_\-th center of ignition. It is guaranteed that the locations of all centers of ignition are distinct. ## Output Print the minimal time it takes the fire to lighten up the whole city (in minutes). [samples] ## Note In the first example the last block can have coordinates (4, 4). In the second example the last block can have coordinates (8, 3).
Berland 的首府看起来是一个由大小相同的正方形街区组成的 $n × m$ 矩形网格。 着火了! 已知有 $k + 1$ 个街区被点燃($k + 1 ≤ n·m$)。这些街区是火源中心。其中 $k$ 个火源中心的位置已知,而第 $(k + 1)$ 个火源中心的位置未知。所有 $k + 1$ 个位置互不相同。 火势传播方式如下:在第 0 分钟时,只有这 $k + 1$ 个火源中心在燃烧。此后每分钟,火势会蔓延到所有与正在燃烧的街区相邻的街区(包括上下左右以及四个对角方向)。可以认为火势会持续燃烧足够长的时间,远超题目所需的时间。相邻街区指与当前街区共享一条边或一个角的街区。 Berland 消防部门希望估算火势蔓延至整个城市所需的最短时间。请注意,已知 $k$ 个火源中心的位置,而第 $(k + 1)$ 个火源中心可以位于任意其他未被占用的街区。 请帮助 Berland 消防部门估算火势蔓延至整个城市所需的最短时间。 第一行包含三个整数 $n$、$m$ 和 $k$($1 ≤ n, m ≤ 10^9$,$1 ≤ k ≤ 500$)。 接下来的 $k$ 行,每行包含两个整数 $x_i$ 和 $y_i$($1 ≤ x_i ≤ n$,$1 ≤ y_i ≤ m$)——第 $i$ 个火源中心的坐标。保证所有火源中心的位置互不相同。 请输出火势蔓延至整个城市所需的最短时间(以分钟为单位)。 在第一个示例中,最后一个火源中心的坐标可以是 $(4, 4)$。 在第二个示例中,最后一个火源中心的坐标可以是 $(8, 3)$。 ## Input 第一行包含三个整数 $n$、$m$ 和 $k$($1 ≤ n, m ≤ 10^9$,$1 ≤ k ≤ 500$)。接下来的 $k$ 行,每行包含两个整数 $x_i$ 和 $y_i$($1 ≤ x_i ≤ n$,$1 ≤ y_i ≤ m$)——第 $i$ 个火源中心的坐标。保证所有火源中心的位置互不相同。 ## Output 请输出火势蔓延至整个城市所需的最短时间(以分钟为单位)。 [samples] ## Note 在第一个示例中,最后一个火源中心的坐标可以是 $(4, 4)$。在第二个示例中,最后一个火源中心的坐标可以是 $(8, 3)$。
**Definitions** Let $ n, m \in \mathbb{Z}^+ $ denote the dimensions of the grid (rows × columns). Let $ k \in \mathbb{Z}^+ $ with $ k \leq 500 $ denote the number of known fire sources. Let $ S = \{ (x_i, y_i) \in \{1, \dots, n\} \times \{1, \dots, m\} \mid i = 1, \dots, k \} $ be the set of known ignition centers. Let $ p \in (\{1, \dots, n\} \times \{1, \dots, m\}) \setminus S $ be the unknown ignition center (to be chosen optimally). Let $ F = S \cup \{p\} $ be the full set of $ k+1 $ ignition centers. The fire spreads in **Chebyshev distance**: at each minute, it reaches all 8 neighboring cells (Moore neighborhood). Thus, the time for fire to reach a cell $ (x, y) $ from a source $ (x_i, y_i) $ is $ \max(|x - x_i|, |y - y_i|) $. **Constraints** 1. $ 1 \leq n, m \leq 10^9 $ 2. $ 1 \leq k \leq 500 $ 3. All points in $ S $ are distinct. 4. $ p \notin S $, and $ p $ is chosen adversarially to **minimize** the total fire spread time. **Objective** Compute: $$ \min_{p \in (\{1,\dots,n\} \times \{1,\dots,m\}) \setminus S} \left( \max_{(x,y) \in \{1,\dots,n\} \times \{1,\dots,m\}} \min_{(x_i,y_i) \in F} \max(|x - x_i|, |y - y_i|) \right) $$ That is, choose the unknown ignition point $ p $ to minimize the **maximum Chebyshev distance** from any cell in the grid to the nearest ignition center in $ F = S \cup \{p\} $.
Samples
Input #1
7 7 3
1 2
2 1
5 5
Output #1
3
Input #2
10 5 1
3 3
Output #2
2
API Response (JSON)
{
  "problem": {
    "name": "E. Fire in the City",
    "description": {
      "content": "The capital of Berland looks like a rectangle of size _n_ × _m_ of the square blocks of same size. Fire! It is known that _k_ + 1 blocks got caught on fire (_k_ + 1 ≤ _n_·_m_). Those blocks are cent",
      "description_type": "Markdown"
    },
    "platform": "Codeforces",
    "limit": {
      "time_limit": 2000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "CF845E"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "The capital of Berland looks like a rectangle of size _n_ × _m_ of the square blocks of same size.\n\nFire!\n\nIt is known that _k_ + 1 blocks got caught on fire (_k_ + 1 ≤ _n_·_m_). Those blocks are cent...",
      "is_translate": false,
      "language": "English"
    },
    {
      "statement_type": "Markdown",
      "content": "Berland 的首府看起来是一个由大小相同的正方形街区组成的 $n × m$ 矩形网格。\n\n着火了!\n\n已知有 $k + 1$ 个街区被点燃($k + 1 ≤ n·m$)。这些街区是火源中心。其中 $k$ 个火源中心的位置已知,而第 $(k + 1)$ 个火源中心的位置未知。所有 $k + 1$ 个位置互不相同。\n\n火势传播方式如下:在第 0 分钟时,只有这 $k + 1$ 个火源中心在燃烧。此...",
      "is_translate": true,
      "language": "Chinese"
    },
    {
      "statement_type": "Markdown",
      "content": "**Definitions**  \nLet $ n, m \\in \\mathbb{Z}^+ $ denote the dimensions of the grid (rows × columns).  \nLet $ k \\in \\mathbb{Z}^+ $ with $ k \\leq 500 $ denote the number of known fire sources.  \nLet $ S ...",
      "is_translate": false,
      "language": "Formal"
    }
  ]
}
Full JSON Raw Segments