A. One-dimensional Japanese Crossword

Codeforces
IDCF721A
Time1000ms
Memory256MB
Difficulty
implementation
English · Original
Chinese · Translation
Formal · Original
Recently Adaltik discovered japanese crosswords. Japanese crossword is a picture, represented as a table sized _a_ × _b_ squares, and each square is colored white or black. There are integers to the left of the rows and to the top of the columns, encrypting the corresponding row or column. The number of integers represents how many groups of black squares there are in corresponding row or column, and the integers themselves represents the number of consecutive black squares in corresponding group (you can find more detailed explanation in Wikipedia [https://en.wikipedia.org/wiki/Japanese_crossword](https://en.wikipedia.org/wiki/Japanese_crossword)). Adaltik decided that the general case of japanese crossword is too complicated and drew a row consisting of _n_ squares (e.g. japanese crossword sized 1 × _n_), which he wants to encrypt in the same way as in japanese crossword. <center>![image](https://espresso.codeforces.com/24409f1ba174394574276be0879d56f4b455ece1.png) The example of encrypting of a single row of japanese crossword.</center>Help Adaltik find the numbers encrypting the row he drew. ## Input The first line of the input contains a single integer _n_ (1 ≤ _n_ ≤ 100) — the length of the row. The second line of the input contains a single string consisting of _n_ characters '_B_' or '_W_', ('_B_' corresponds to black square, '_W_' — to white square in the row that Adaltik drew). ## Output The first line should contain a single integer _k_ — the number of integers encrypting the row, e.g. the number of groups of black squares in the row. The second line should contain _k_ integers, encrypting the row, e.g. corresponding to sizes of groups of consecutive black squares in the order from left to right. [samples] ## Note The last sample case correspond to the picture in the statement.
最近,Adaltik 发现了日本填字谜题。日本填字谜题是一幅图像,表示为一个大小为 $a × b$ 的表格,每个格子为白色或黑色。在每行的左侧和每列的上方标有整数,用于加密对应的行或列。这些整数的个数表示该行或列中黑色格子组成的连续段的数量,而每个整数本身表示对应连续段中黑色格子的个数(更详细的解释请参见维基百科 https://en.wikipedia.org/wiki/Japanese_crossword)。 Adaltik 认为一般的日本填字谜题过于复杂,于是画了一行包含 $n$ 个格子的序列(例如一个 $1 × n$ 的日本填字谜题),并希望以与日本填字谜题相同的方式对其进行加密。 请帮助 Adaltik 找出加密他所画行的整数序列。 输入的第一行包含一个整数 $n$($1 ≤ n ≤ 100$)— 行的长度。第二行包含一个由 $n$ 个字符 '_'B_' 或 '_'W_' 组成的字符串('_'B_' 表示黑色格子,'_'W_' 表示白色格子,对应 Adaltik 所画的行)。 第一行应输出一个整数 $k$ —— 加密该行的整数个数,即行中黑色格子连续段的数量。 第二行应输出 $k$ 个整数,表示加密结果,即从左到右每个连续黑色格子段的长度。 ## Input 输入的第一行包含一个整数 $n$($1 ≤ n ≤ 100$)— 行的长度。第二行包含一个由 $n$ 个字符 '_'B_' 或 '_'W_' 组成的字符串('_'B_' 表示黑色格子,'_'W_' 表示白色格子,对应 Adaltik 所画的行)。 ## Output 第一行应输出一个整数 $k$ —— 加密该行的整数个数,即行中黑色格子连续段的数量。第二行应输出 $k$ 个整数,表示加密结果,即从左到右每个连续黑色格子段的长度。 [samples] ## Note 最后一个样例对应题面中的图示。
Let $ n \in \mathbb{N} $, $ 1 \leq n \leq 100 $, and let $ s \in \{B, W\}^n $ be a string representing a row of $ n $ squares, where $ B $ denotes a black square and $ W $ denotes a white square. Define the sequence of black groups as follows: - Traverse $ s $ from left to right. - A **group** is a maximal contiguous subsequence of $ B $'s. - Let $ k $ be the number of such groups. - Let $ g_1, g_2, \dots, g_k $ be the lengths of these groups in order. Output: - $ k $ - $ g_1, g_2, \dots, g_k $
Samples
Input #1
3
BBW
Output #1
1
2
Input #2
5
BWBWB
Output #2
3
1 1 1
Input #3
4
WWWW
Output #3
0
Input #4
4
BBBB
Output #4
1
4
Input #5
13
WBBBBWWBWBBBW
Output #5
3
4 1 3
API Response (JSON)
{
  "problem": {
    "name": "A. One-dimensional Japanese Crossword",
    "description": {
      "content": "Recently Adaltik discovered japanese crosswords. Japanese crossword is a picture, represented as a table sized _a_ × _b_ squares, and each square is colored white or black. There are integers to the l",
      "description_type": "Markdown"
    },
    "platform": "Codeforces",
    "limit": {
      "time_limit": 1000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "CF721A"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "Recently Adaltik discovered japanese crosswords. Japanese crossword is a picture, represented as a table sized _a_ × _b_ squares, and each square is colored white or black. There are integers to the l...",
      "is_translate": false,
      "language": "English"
    },
    {
      "statement_type": "Markdown",
      "content": "最近,Adaltik 发现了日本填字谜题。日本填字谜题是一幅图像,表示为一个大小为 $a × b$ 的表格,每个格子为白色或黑色。在每行的左侧和每列的上方标有整数,用于加密对应的行或列。这些整数的个数表示该行或列中黑色格子组成的连续段的数量,而每个整数本身表示对应连续段中黑色格子的个数(更详细的解释请参见维基百科 https://en.wikipedia.org/wiki/Japanese_cro...",
      "is_translate": true,
      "language": "Chinese"
    },
    {
      "statement_type": "Markdown",
      "content": "Let $ n \\in \\mathbb{N} $, $ 1 \\leq n \\leq 100 $, and let $ s \\in \\{B, W\\}^n $ be a string representing a row of $ n $ squares, where $ B $ denotes a black square and $ W $ denotes a white square.\n\nDef...",
      "is_translate": false,
      "language": "Formal"
    }
  ]
}
Full JSON Raw Segments