LIDS

AtCoder
IDagc059_f
Time4000ms
Memory256MB
Difficulty
Given $N, pos, val$, find the number of permutations $P=(P_1, P_2, \ldots, P_N)$ of $(1,2,\ldots,N)$ that satisfy all of the following conditions, modulo $10^9+7$: * $LIS(P) + LDS(P) = N+1$ * $P_{pos} = val$ Here, $LIS(P)$ denotes the length of the longest increasing subsequence of $P$, and $LDS(P)$ denotes the length of the longest decreasing subsequence of $P$. ## Constraints * $1 \le N \le 5\cdot 10^6$ * $1 \le pos, val \le N$ * All values in the input are integers. ## Input Input is given from Standard Input in the following format: $N$ $pos$ $val$ [samples]
Samples
Input #1
3 2 2
Output #1
2

The following permutations satisfy the conditions: $(1, 2, 3), (3, 2, 1)$.
Input #2
4 1 1
Output #2
6

The following permutations satisfy the conditions: $(1, 2, 3, 4), (1, 2, 4, 3), (1, 3, 2, 4), (1, 3, 4, 2), (1, 4, 2, 3), (1, 4, 3, 2)$.
Input #3
5 2 5
Output #3
11
Input #4
2022 69 420
Output #4
128873576
API Response (JSON)
{
  "problem": {
    "name": "LIDS",
    "description": {
      "content": "Given $N, pos, val$, find the number of permutations $P=(P_1, P_2, \\ldots, P_N)$ of $(1,2,\\ldots,N)$ that satisfy all of the following conditions, modulo $10^9+7$: *   $LIS(P) + LDS(P) = N+1$ *   $P_",
      "description_type": "Markdown"
    },
    "platform": "AtCoder",
    "limit": {
      "time_limit": 4000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "agc059_f"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "Given $N, pos, val$, find the number of permutations $P=(P_1, P_2, \\ldots, P_N)$ of $(1,2,\\ldots,N)$ that satisfy all of the following conditions, modulo $10^9+7$:\n\n*   $LIS(P) + LDS(P) = N+1$\n*   $P_...",
      "is_translate": false,
      "language": "English"
    }
  ]
}
Full JSON Raw Segments