E. Qwerty78 Trip

Codeforces
IDCF10094E
Time2000ms
Memory64MB
Difficulty
English · Original
Formal · Original
_Qwerty78_ is a well known programmer (He is a member of the ICPC WF winning team in 2015, a topcoder target and one of codeforces top 10). He wants to go to Dreamoon's house to apologize to him, after he ruined his plans in winning a Div2 contest (He participated using the handle _"sorry_Dreamoon"_) so he came first and Dreamoon came second. Their houses are presented on a grid of N rows and M columns. Qwerty78 house is at the cell (1, 1) and Dreamoon's house is at the cell (N, M). If Qwerty78 is standing on a cell (r, c) he can go to the cell (r + 1, c) or to the cell (r, c + 1). Unfortunately Dreamoon expected Qwerty78 visit , so he put exactly 1 obstacle in this grid (neither in his house nor in Qwerty78's house) to challenge Qwerty78. Qwerty78 can't enter a cell which contains an obstacle. Dreamoon sent Qwerty78 a message "In how many ways can you reach my house?". Your task is to help Qwerty78 and count the number of ways he can reach Dreamoon's house. Since the answer is too large , you are asked to calculate it modulo 109 + 7 . The first line containts a single integer T , the number of testcases. Then T testcases are given as follows : The first line of each testcase contains two space-separated N , M ( 2 ≤ N, M ≤ 105) The second line of each testcase contains 2 space-separated integers OR, OC - the coordinates of the blocked cell (1 ≤ OR ≤ N) (1 ≤ OC ≤ M). Output T lines , The answer for each testcase which is the number of ways Qwerty78 can reach Dreamoon's house modulo 109 + 7. Sample testcase Explanation : The grid has the following form: _Q*._ _..D_ Only one valid path: _(1,1)_ to _(2,1)_ to _(2,2)_ to _(2,3)_. ## Input The first line containts a single integer T , the number of testcases.Then T testcases are given as follows :The first line of each testcase contains two space-separated N , M ( 2 ≤ N, M ≤ 105)The second line of each testcase contains 2 space-separated integers OR, OC - the coordinates of the blocked cell (1 ≤ OR ≤ N) (1 ≤ OC ≤ M). ## Output Output T lines , The answer for each testcase which is the number of ways Qwerty78 can reach Dreamoon's house modulo 109 + 7. [samples] ## Note Sample testcase Explanation :The grid has the following form:_Q*.__..D_Only one valid path:_(1,1)_ to _(2,1)_ to _(2,2)_ to _(2,3)_.
**Definitions** Let $ T \in \mathbb{Z} $ be the number of test cases. For each test case: - Let $ N, M \in \mathbb{Z} $ denote the grid dimensions, with $ 2 \leq N, M \leq 10^5 $. - Let $ (r_b, c_b) \in \{1, \dots, N\} \times \{1, \dots, M\} $ be the coordinates of the single obstacle, with $ (r_b, c_b) \neq (1,1) $ and $ (r_b, c_b) \neq (N,M) $. - Let $ P = \{(i,j) \mid 1 \leq i \leq N, 1 \leq j \leq M\} $ be the set of grid cells. - A valid path is a sequence of cells from $ (1,1) $ to $ (N,M) $, moving only right ($ (r,c) \to (r,c+1) $) or down ($ (r,c) \to (r+1,c) $), avoiding $ (r_b, c_b) $. **Constraints** 1. $ 1 \leq T \leq \text{unknown (but bounded by input size)} $ 2. $ 2 \leq N, M \leq 10^5 $ 3. $ 1 \leq r_b \leq N $, $ 1 \leq c_b \leq M $, $ (r_b, c_b) \notin \{(1,1), (N,M)\} $ **Objective** For each test case, compute the number of valid paths from $ (1,1) $ to $ (N,M) $ avoiding $ (r_b, c_b) $, modulo $ 10^9 + 7 $: $$ \text{Answer} = \binom{N+M-2}{N-1} - \left( \binom{r_b + c_b - 2}{r_b - 1} \cdot \binom{N - r_b + M - c_b}{N - r_b} \right) \pmod{10^9 + 7} $$
API Response (JSON)
{
  "problem": {
    "name": "E. Qwerty78 Trip",
    "description": {
      "content": "_Qwerty78_ is a well known programmer (He is a member of the ICPC WF winning team in 2015, a topcoder target and one of codeforces top 10).  He wants to go to Dreamoon's house to apologize to him, af",
      "description_type": "Markdown"
    },
    "platform": "Codeforces",
    "limit": {
      "time_limit": 2000,
      "memory_limit": 65536
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "CF10094E"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "_Qwerty78_ is a well known programmer (He is a member of the ICPC WF winning team in 2015, a topcoder target and one of codeforces top 10). \n\nHe wants to go to Dreamoon's house to apologize to him, af...",
      "is_translate": false,
      "language": "English"
    },
    {
      "statement_type": "Markdown",
      "content": "**Definitions**  \nLet $ T \\in \\mathbb{Z} $ be the number of test cases.  \nFor each test case:  \n- Let $ N, M \\in \\mathbb{Z} $ denote the grid dimensions, with $ 2 \\leq N, M \\leq 10^5 $.  \n- Let $ (r_b...",
      "is_translate": false,
      "language": "Formal"
    }
  ]
}
Full JSON Raw Segments