LR Constraints

AtCoder
IDarc124_a
Time2000ms
Memory256MB
Difficulty
We have $N$ cards arranged in a row from left to right. We will write an integer between $1$ and $K$ (inclusive) on each of these cards, which are initially blank. Given are $K$ restrictions numbered $1$ through $K$. Restriction $i$ is composed of a character $c_i$ and an integer $k_i$. If $c_i$ is `L`, the $k_i$\-th card from the left in the row must be the **leftmost** card on which we write $i$. If $c_i$ is `R`, the $k_i$\-th card from the left in the row must be the **rightmost** card on which we write $i$. Note that for each integer $i$ from $1$ through $K$, there must be at least one card on which we write $i$. Find the number of ways to write integers on the cards under the $K$ restrictions, modulo $998244353$. ## Constraints * $1 \leq N,K \leq 1000$ * $c_i$ is `L` or `R`. * $1 \leq k_i \leq N$ * $k_i \neq k_j$ if $i \neq j$. ## Input Input is given from Standard Input in the following format: $N$ $K$ $c_1$ $k_1$ $\vdots$ $c_K$ $k_K$ [samples]
Samples
Input #1
3 2
L 1
R 2
Output #1
1

*   The only way to meet the two restrictions is to write $1, 2, 1$ from left to right on the three cards.
Input #2
30 10
R 6
R 8
R 7
R 25
L 26
L 13
R 14
L 11
L 23
R 30
Output #2
343921442

*   Be sure to find the count modulo $998244353$.
API Response (JSON)
{
  "problem": {
    "name": "LR Constraints",
    "description": {
      "content": "We have $N$ cards arranged in a row from left to right. We will write an integer between $1$ and $K$ (inclusive) on each of these cards, which are initially blank. Given are $K$ restrictions numbered ",
      "description_type": "Markdown"
    },
    "platform": "AtCoder",
    "limit": {
      "time_limit": 2000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "arc124_a"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "We have $N$ cards arranged in a row from left to right. We will write an integer between $1$ and $K$ (inclusive) on each of these cards, which are initially blank.\nGiven are $K$ restrictions numbered ...",
      "is_translate": false,
      "language": "English"
    }
  ]
}
Full JSON Raw Segments