Back and Forth Filling

AtCoder
IDabc430_f
Time2000ms
Memory256MB
Difficulty
You are given an integer $N$ and a string $S$ of length $N-1$ consisting of `L` and `R`. Consider writing integers into $N$ cells arranged in a row so that the following conditions are satisfied: * Every cell has one integer written on it. * Every integer $1,2,\dots,N$ appears in exactly one cell. * When the $i$\-th character of $S$ is `L`, $i+1$ is written to the left of $i$. * When the $i$\-th character of $S$ is `R`, $i+1$ is written to the right of $i$. Let $C_i$ be the number of integers that can be written in the $i$\-th cell from the left. Find $C_1,C_2,\dots,C_N$. You are given $T$ test cases; find the answer for each of them. ## Constraints * $1 \le T \le 20000$ * $2 \le N \le 3 \times 10^5$ * $S$ is a string of length $N-1$ consisting of `L` and `R`. * For a single input, the sum of $N$ does not exceed $3 \times 10^5$. ## Input The input is given from Standard Input in the following format: $T$ $\text{case}_1$ $\text{case}_2$ $\vdots$ $\text{case}_T$ Each test case is given in the following format: $N$ $S$ [samples]
Samples
Input #1
5
5
RLLR
3
RL
2
L
3
RR
20
RLLLLLLLLRLRRLLLRLR
Output #1
2 4 3 4 2
2 2 1
1 1
1 1 1
5 9 13 14 15 17 18 19 19 20 20 19 19 18 17 16 14 12 9 5

This input contains five test cases.

*   For the first test case, there are $11$ possible ways to fill the cells as follows:
    *   $(1,4,3,2,5)$
    *   $(1,4,3,5,2)$
    *   $(1,4,5,3,2)$
    *   $(4,1,3,2,5)$
    *   $(4,1,3,5,2)$
    *   $(4,1,5,3,2)$
    *   $(4,3,1,2,5)$
    *   $(4,3,1,5,2)$
    *   $(4,3,5,1,2)$
    *   $(4,5,1,3,2)$
    *   $(4,5,3,1,2)$
*   From this, each value of $C_i$ is determined as follows:
    *   The integers that can be written in the $1$\-st cell from the left are $1,4$, which is two integers.
    *   The integers that can be written in the $2$\-nd cell from the left are $1,3,4,5$, which is four integers.
    *   The integers that can be written in the $3$\-rd cell from the left are $1,3,5$, which is three integers.
    *   The integers that can be written in the $4$\-th cell from the left are $1,2,3,5$, which is four integers.
    *   The integers that can be written in the $5$\-th cell from the left are $2,5$, which is two integers.
*   For the second test case, there are two possible ways to fill the cells as follows:
    *   $(1,3,2)$
    *   $(3,1,2)$
*   For the third test case, there is one possible way to fill the cells as follows:
    *   $(2,1)$
*   For the fourth test case, there is one possible way to fill the cells as follows:
    *   $(1,2,3)$
API Response (JSON)
{
  "problem": {
    "name": "Back and Forth Filling",
    "description": {
      "content": "You are given an integer $N$ and a string $S$ of length $N-1$ consisting of `L` and `R`. Consider writing integers into $N$ cells arranged in a row so that the following conditions are satisfied: *  ",
      "description_type": "Markdown"
    },
    "platform": "AtCoder",
    "limit": {
      "time_limit": 2000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "abc430_f"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "You are given an integer $N$ and a string $S$ of length $N-1$ consisting of `L` and `R`.\nConsider writing integers into $N$ cells arranged in a row so that the following conditions are satisfied:\n\n*  ...",
      "is_translate": false,
      "language": "English"
    }
  ]
}
Full JSON Raw Segments