atcoder#ABC294E. [ABC294E] 2xN Grid
[ABC294E] 2xN Grid
Score : points
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.
8 4 3
1 2
3 2
2 3
3 1
1 4
2 1
3 3
4
The grid is shown below.
We have four integers such that : . Thus, you should print .
10000000000 1 1
1 10000000000
1 10000000000
10000000000
Note that the answer may not fit into a -bit integer.
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
380