#abc309h. Ex - Simple Path Counting Problem

Ex - Simple Path Counting Problem

Score : 650650 points

问题描述

我们有一个 NN 行和 MM 列的网格。我们将左起第 jj 列、上起第 ii 行的单元格记为 (i,j)(i,j)

已知整数序列 A=(A1,A2,,AK)A=(A_1,A_2,\dots,A_K)B=(B1,B2,,BL)B=(B_1,B_2,\dots,B_L),其长度分别为 KKLL

对于所有满足 1iK1 \le i \le K1jL1 \le j \le L 的整数对 (i,j)(i,j),求以下问题答案之和并对 998244353998244353 取模。

  • 一个棋子最初放置在点 (1,Ai)(1,A_i)。有多少种路径可以通过重复以下移动 (N1)(N-1) 次将棋子移动到点 (N,Bj)(N,B_j)
    • 假设棋子当前位于单元格 (p,q)(p,q),将其移动至 (p+1,q1)(p+1,q-1)(p+1,q)(p+1,q)(p+1,q+1)(p+1,q+1),且在整个过程中不能移出网格范围。

以上为通义千问 qwen-max 翻译,仅供参考。

Problem Statement

We have a grid with NN rows and MM columns. We denote by (i,j)(i,j) the cell in the ii-th row from the top and jj-th column from the left.

You are given integer sequences A=(A1,A2,,AK)A=(A_1,A_2,\dots,A_K) and B=(B1,B2,,BL)B=(B_1,B_2,\dots,B_L) of lengths KK and LL, respectively.

Find the sum, modulo 998244353998244353, of the answers to the following question over all integer pairs (i,j)(i,j) such that 1iK1 \le i \le K and 1jL1 \le j \le L.

  • A piece is initially placed at (1,Ai)(1,A_i). How many paths are there to take it to (N,Bj)(N,B_j) by repeating the following move (N1)(N-1) times?
    • Let (p,q)(p,q) be the piece's current cell. Move it to (p+1,q1),(p+1,q)(p+1,q-1),(p+1,q), or (p+1,q+1)(p+1,q+1), without moving it outside the grid.

Constraints

  • 1N1091 \le N \le 10^9
  • 1M,K,L1051 \le M,K,L \le 10^5
  • 1Ai,BjM1 \le A_i,B_j \le M

Input

The input is given from Standard Input in the following format:

NN MM KK LL

A1A_1 A2A_2 \dots AKA_K

B1B_1 B2B_2 \dots BLB_L

Output

Print the answer.

Sample Input 1

3 4 1 2
1
1 2

Sample Output 1

4

For (i,j)=(1,1)(i,j)=(1,1), the following two paths are possible:

  • (1,1)(2,1)(3,1)(1,1) \rightarrow (2,1) \rightarrow (3,1)
  • (1,1)(2,2)(3,1)(1,1) \rightarrow (2,2) \rightarrow (3,1)

For (i,j)=(1,2)(i,j)=(1,2), the following two paths are possible:

  • (1,1)(2,1)(3,2)(1,1) \rightarrow (2,1) \rightarrow (3,2)
  • (1,1)(2,2)(3,2)(1,1) \rightarrow (2,2) \rightarrow (3,2)

Thus, the answer is 2+2=42 + 2 =4.

Sample Input 2

5 8 4 5
3 1 4 1
2 7 1 8 2

Sample Output 2

137

Sample Input 3

883671387 87719 10 12
86879 64174 47274 41688 17713 50897 53989 7210 30894 5714
60358 28835 48036 48450 67149 36558 35929 69025 77539 19195 60762 60721

Sample Output 3

941873621

update @ 2024/3/10 08:47:15