C. Seat Arrangements

Codeforces
IDCF919C
Time1000ms
Memory256MB
Difficulty
brute forceimplementation
English · Original
Chinese · Translation
Formal · Original
Suppose that you are in a campus and have to go for classes day by day. As you may see, when you hurry to a classroom, you surprisingly find that many seats there are already occupied. Today you and your friends went for class, and found out that some of the seats were occupied. The classroom contains $n$ rows of seats and there are $m$ seats in each row. Then the classroom can be represented as an $n \times m$ matrix. The character '_._' represents an empty seat, while '_*_' means that the seat is occupied. You need to find $k$ consecutive empty seats in the same row or column and arrange those seats for you and your friends. Your task is to find the number of ways to arrange the seats. **Two ways are considered different if sets of places that students occupy differs.** ## Input The first line contains three positive integers $n,m,k$ ($1 \leq n, m, k \leq 2\,000$), where $n,m$ represent the sizes of the classroom and $k$ is the number of consecutive seats you need to find. Each of the next $n$ lines contains $m$ characters '_._' or '_*_'. They form a matrix representing the classroom, '_._' denotes an empty seat, and '_*_' denotes an occupied seat. ## Output A single number, denoting the number of ways to find $k$ empty seats in the same row or column. [samples] ## Note In the first sample, there are three ways to arrange those seats. You can take the following seats for your arrangement. * $(1,3)$, $(2,3)$ * $(2,2)$, $(2,3)$ * $(2,1)$, $(2,2)$
假设你身处校园,每天都要去上课。你会发现,当你匆忙赶往教室时,许多座位已经被占用了。今天你和朋友们去上课,发现有一些座位已经被占用。 教室中有 $n$ 行座位,每行有 $m$ 个座位。因此,教室可以表示为一个 $n \times m$ 的矩阵。字符 '_._' 表示空座位,而 '_*_' 表示座位已被占用。你需要在同行或同列中找到 $k$ 个连续的空座位,并为你们和朋友安排这些座位。你的任务是计算安排座位的方法数。*两种方式不同当且仅当学生占据的座位集合不同。* 第一行包含三个正整数 $n, m, k$($1 lt.eq n, m, k lt.eq 2 thin 000$),其中 $n, m$ 表示教室的尺寸,$k$ 是你需要找到的连续座位数。 接下来的 $n$ 行每行包含 $m$ 个字符 '_._' 或 '_*_',构成表示教室的矩阵,'_._' 表示空座位,'_*_' 表示被占用的座位。 输出一个数字,表示在同行或同列中找到 $k$ 个连续空座位的方法数。 在第一个样例中,有三种方式可以安排这些座位。你可以选择以下座位进行安排: ## Input 第一行包含三个正整数 $n, m, k$($1 lt.eq n, m, k lt.eq 2 thin 000$),其中 $n, m$ 表示教室的尺寸,$k$ 是你需要找到的连续座位数。接下来的 $n$ 行每行包含 $m$ 个字符 '_._' 或 '_*_',构成表示教室的矩阵,'_._' 表示空座位,'_*_' 表示被占用的座位。 ## Output 输出一个数字,表示在同行或同列中找到 $k$ 个连续空座位的方法数。 [samples] ## Note 在第一个样例中,有三种方式可以安排这些座位。你可以选择以下座位进行安排: $(1, 3)$, $(2, 3)$ $(2, 2)$, $(2, 3)$ $(2, 1)$, $(2, 2)$
**Definitions** Let $ n, m, k \in \mathbb{Z}^+ $ with $ 1 \leq n, m, k \leq 2000 $. Let $ M \in \{ '.', '*' \}^{n \times m} $ be a binary matrix where $ M_{i,j} = '.' $ denotes an empty seat and $ M_{i,j} = '*' $ denotes an occupied seat. **Constraints** 1. $ 1 \leq n, m, k \leq 2000 $ 2. For all $ i \in \{1, \dots, n\}, j \in \{1, \dots, m\} $, $ M_{i,j} \in \{ '.', '*' \} $ **Objective** Count the number of ways to select a contiguous block of exactly $ k $ empty seats ($ '.' $) in a single row or column. Let $ R $ be the set of all horizontal segments of length $ k $: For each row $ i \in \{1, \dots, n\} $, and each starting column $ j \in \{1, \dots, m - k + 1\} $, define segment $ H_{i,j} = \{ (i,j), (i,j+1), \dots, (i,j+k-1) \} $. $ H_{i,j} $ is valid iff $ M_{i,j'} = '.' $ for all $ j' \in \{j, j+1, \dots, j+k-1\} $. Let $ C $ be the set of all vertical segments of length $ k $: For each column $ j \in \{1, \dots, m\} $, and each starting row $ i \in \{1, \dots, n - k + 1\} $, define segment $ V_{i,j} = \{ (i,j), (i+1,j), \dots, (i+k-1,j) \} $. $ V_{i,j} $ is valid iff $ M_{i',j} = '.' $ for all $ i' \in \{i, i+1, \dots, i+k-1\} $. The objective is: $$ \left| \left\{ H_{i,j} \mid \text{valid} \right\} \cup \left\{ V_{i,j} \mid \text{valid} \right\} \right| $$
Samples
Input #1
2 3 2
**.
...
Output #1
3
Input #2
1 2 2
..
Output #2
1
Input #3
3 3 4
.*.
*.*
.*.
Output #3
0
API Response (JSON)
{
  "problem": {
    "name": "C. Seat Arrangements",
    "description": {
      "content": "Suppose that you are in a campus and have to go for classes day by day. As you may see, when you hurry to a classroom, you surprisingly find that many seats there are already occupied. Today you and y",
      "description_type": "Markdown"
    },
    "platform": "Codeforces",
    "limit": {
      "time_limit": 1000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "CF919C"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "Suppose that you are in a campus and have to go for classes day by day. As you may see, when you hurry to a classroom, you surprisingly find that many seats there are already occupied. Today you and y...",
      "is_translate": false,
      "language": "English"
    },
    {
      "statement_type": "Markdown",
      "content": "假设你身处校园,每天都要去上课。你会发现,当你匆忙赶往教室时,许多座位已经被占用了。今天你和朋友们去上课,发现有一些座位已经被占用。\n\n教室中有 $n$ 行座位,每行有 $m$ 个座位。因此,教室可以表示为一个 $n \\times m$ 的矩阵。字符 '_._' 表示空座位,而 '_*_' 表示座位已被占用。你需要在同行或同列中找到 $k$ 个连续的空座位,并为你们和朋友安排这些座位。你的任务是计...",
      "is_translate": true,
      "language": "Chinese"
    },
    {
      "statement_type": "Markdown",
      "content": "**Definitions**  \nLet $ n, m, k \\in \\mathbb{Z}^+ $ with $ 1 \\leq n, m, k \\leq 2000 $.  \nLet $ M \\in \\{ '.', '*' \\}^{n \\times m} $ be a binary matrix where $ M_{i,j} = '.' $ denotes an empty seat and $...",
      "is_translate": false,
      "language": "Formal"
    }
  ]
}
Full JSON Raw Segments