#abc294e. E - 2xN Grid
E - 2xN Grid
Score : points
问题描述
我们有一个包含2行和列的网格。令表示从上数第行(其中)且从左数第列()的方格。在上写有一个整数。
找出满足的整数的数量。
这里,对的描述以运行长度压缩的形式给出:分别将和压缩为长度分别为和的序列:$((v _ {1,1},l _ {1,1}),\ldots,(v _ {1,N _ 1},l _ {1,N _ 1}))$和$((v _ {2,1},l _ {2,1}),\ldots,(v _ {2,N _ 2},l _ {2,N _ 2}))$。
这里,序列的运行长度压缩是指通过以下方式获得的一系列元素值和正整数构成的对序列。
- 在每对相邻不同元素之间分割。
- 对于分割后的每个子序列,令为中的元素,为的长度。
以上为通义千问 qwen-max 翻译,仅供参考。
Problem Statement
We have a grid with rows and columns. Let denote the square at the -th row from the top and -th column from the left . has an integer written on it.
Find the number of integers such that .
Here, the description of is given to you as the run-length compressions of and into sequences of lengths and , respectively: $((v _ {1,1},l _ {1,1}),\ldots,(v _ {1,N _ 1},l _ {1,N _ 1}))$ and $((v _ {2,1},l _ {2,1}),\ldots,(v _ {2,N _ 2},l _ {2,N _ 2}))$.
Here, the run-length compression of a sequence is a sequence of pairs of an element of and a positive integer obtained as follows.
- Split between each pair of different adjacent elements.
- For each sequence after the split, let be the element of and be the length of .
Constraints
- $1\leq v _ {i,j}\leq 10 ^ 9\ (i\in\lbrace1,2\rbrace,1\leq j\leq N _ i)$
- $1\leq l _ {i,j}\leq L\ (i\in\lbrace1,2\rbrace,1\leq j\leq N _ i)$
- $v _ {i,j}\neq v _ {i,j+1}\ (i\in\lbrace1,2\rbrace,1\leq j\lt N _ i)$
- $l _ {i,1}+l _ {i,2}+\cdots+l _ {i,N _ i}=L\ (i\in\lbrace1,2\rbrace)$
- All values in the input are integers.
Input
The input is given from Standard Input in the following format:
Output
Print a single line containing the answer.
Sample Input 1
8 4 3
1 2
3 2
2 3
3 1
1 4
2 1
3 3
Sample Output 1
4
The grid is shown below.
We have four integers such that : . Thus, you should print .
Sample Input 2
10000000000 1 1
1 10000000000
1 10000000000
Sample Output 2
10000000000
Note that the answer may not fit into a -bit integer.
Sample Input 3
1000 4 7
19 79
33 463
19 178
33 280
19 255
33 92
34 25
19 96
12 11
19 490
33 31
Sample Output 3
380
update @ 2024/3/10 12:14:42