B. Marlin

Codeforces
IDCF980B
Time1000ms
Memory256MB
Difficulty
constructive algorithms
English · Original
Chinese · Translation
Formal · Original
The city of Fishtopia can be imagined as a grid of $4$ rows and an **odd** number of columns. It has two main villages; the first is located at the top-left cell $(1,1)$, people who stay there love fishing at the Tuna pond at the bottom-right cell $(4, n)$. The second village is located at $(4, 1)$ and its people love the Salmon pond at $(1, n)$. The mayor of Fishtopia wants to place $k$ hotels in the city, each one occupying one cell. To allow people to enter the city from anywhere, hotels should not be placed on the border cells. A person can move from one cell to another if those cells are not occupied by hotels and share a side. Can you help the mayor place the hotels in a way such that there are equal number of shortest paths from each village to its preferred pond? ## Input The first line of input contain two integers, $n$ and $k$ ($3 \leq n \leq 99$, $0 \leq k \leq 2\times(n-2)$), $n$ is **odd**, the width of the city, and the number of hotels to be placed, respectively. ## Output Print "_YES_", if it is possible to place all the hotels in a way that satisfies the problem statement, otherwise print "_NO_". If it is possible, print an extra $4$ lines that describe the city, each line should have $n$ characters, each of which is "_#_" if that cell has a hotel on it, or "_._" if not. [samples]
鱼拓城可以被想象为一个 4 行、列数为 *奇数* 的网格。该城有两个主要村庄:第一个村庄位于左上角单元格 $(1, 1)$,那里的居民喜欢到右下角单元格 $(4, n)$ 的金枪鱼池钓鱼;第二个村庄位于 $(4, 1)$,其居民喜欢位于 $(1, n)$ 的鲑鱼池。 鱼拓城的市长希望在城市中放置 $k$ 家酒店,每家酒店占据一个单元格。为了使人们可以从任何地方进入城市,酒店不能放置在边界单元格上。 一个人可以从一个单元格移动到另一个单元格,当且仅当这两个单元格均未被酒店占据且共享一条边。 你能否帮助市长安排酒店的位置,使得从每个村庄到其偏好池塘的最短路径数量相等? 输入的第一行包含两个整数 $n$ 和 $k$($3 lt.eq n lt.eq 99$,$0 lt.eq k lt.eq 2 times (n -2)$),其中 $n$ 为城市的宽度(奇数),$k$ 为要放置的酒店数量。 如果存在一种放置所有酒店的方式满足题意,则输出 "_YES_",否则输出 "_NO_"。 如果可能,请额外输出 4 行,描述城市布局,每行包含 $n$ 个字符,若该单元格有酒店则为 "_#_",否则为 "_._"。 ## Input 输入的第一行包含两个整数 $n$ 和 $k$($3 lt.eq n lt.eq 99$,$0 lt.eq k lt.eq 2 times (n -2)$),其中 $n$ 为城市的宽度(奇数),$k$ 为要放置的酒店数量。 ## Output 如果存在一种放置所有酒店的方式满足题意,则输出 "_YES_",否则输出 "_NO_"。如果可能,请额外输出 4 行,描述城市布局,每行包含 $n$ 个字符,若该单元格有酒店则为 "_#_",否则为 "_._"。 [samples]
**Definitions** Let $ n \in \mathbb{Z} $ be an odd integer with $ 3 \leq n \leq 99 $, representing the number of columns in a $ 4 \times n $ grid. Let $ k \in \mathbb{Z} $ with $ 0 \leq k \leq 2(n - 2) $, representing the number of hotels to place. The grid has rows $ \{1, 2, 3, 4\} $ and columns $ \{1, \dots, n\} $. Border cells are those with row $ \in \{1, 4\} $ or column $ \in \{1, n\} $. Internal (non-border) cells are those with row $ \in \{2, 3\} $ and column $ \in \{2, \dots, n-1\} $. There are $ 2(n - 2) $ internal cells available for hotel placement. Two source-target pairs: - Village A: $ (1, 1) \to $ Pond A: $ (4, n) $ - Village B: $ (4, 1) \to $ Pond B: $ (1, n) $ A path is a sequence of adjacent (sharing a side) non-hotel cells. A shortest path moves only right and down (for A) or only right and up (for B). Let $ P_A(S) $ denote the number of shortest paths from $ (1,1) $ to $ (4,n) $ in grid $ S $, and $ P_B(S) $ denote the number of shortest paths from $ (4,1) $ to $ (1,n) $ in grid $ S $, where $ S \subseteq \text{internal cells} $ is the set of cells occupied by hotels. **Constraints** 1. $ n $ is odd, $ 3 \leq n \leq 99 $ 2. $ 0 \leq k \leq 2(n - 2) $ 3. Hotels are placed only in internal cells: $ S \subseteq \{2,3\} \times \{2, \dots, n-1\} $, $ |S| = k $ **Objective** Determine whether there exists a set $ S $ of $ k $ internal cells such that: $$ P_A(S) = P_B(S) $$ If yes, output "YES" and a $ 4 \times n $ grid representation with `#` for hotels and `.` otherwise. If no, output "NO".
Samples
Input #1
7 2
Output #1
YES
.......
.#.....
.#.....
.......
Input #2
5 3
Output #2
YES
.....
.###.
.....
.....
API Response (JSON)
{
  "problem": {
    "name": "B. Marlin",
    "description": {
      "content": "The city of Fishtopia can be imagined as a grid of $4$ rows and an **odd** number of columns. It has two main villages; the first is located at the top-left cell $(1,1)$, people who stay there love fi",
      "description_type": "Markdown"
    },
    "platform": "Codeforces",
    "limit": {
      "time_limit": 1000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "CF980B"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "The city of Fishtopia can be imagined as a grid of $4$ rows and an **odd** number of columns. It has two main villages; the first is located at the top-left cell $(1,1)$, people who stay there love fi...",
      "is_translate": false,
      "language": "English"
    },
    {
      "statement_type": "Markdown",
      "content": "鱼拓城可以被想象为一个 4 行、列数为 *奇数* 的网格。该城有两个主要村庄:第一个村庄位于左上角单元格 $(1, 1)$,那里的居民喜欢到右下角单元格 $(4, n)$ 的金枪鱼池钓鱼;第二个村庄位于 $(4, 1)$,其居民喜欢位于 $(1, n)$ 的鲑鱼池。\n\n鱼拓城的市长希望在城市中放置 $k$ 家酒店,每家酒店占据一个单元格。为了使人们可以从任何地方进入城市,酒店不能放置在边界单元格上...",
      "is_translate": true,
      "language": "Chinese"
    },
    {
      "statement_type": "Markdown",
      "content": "**Definitions**  \nLet $ n \\in \\mathbb{Z} $ be an odd integer with $ 3 \\leq n \\leq 99 $, representing the number of columns in a $ 4 \\times n $ grid.  \nLet $ k \\in \\mathbb{Z} $ with $ 0 \\leq k \\leq 2(n...",
      "is_translate": false,
      "language": "Formal"
    }
  ]
}
Full JSON Raw Segments