Upload code_segments/segment_189.txt with huggingface_hub
Browse files
code_segments/segment_189.txt
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
There is a grid, consisting of $2$ rows and $n$ columns. Each cell of the grid is either free or blocked.
|
| 2 |
+
|
| 3 |
+
A free cell $y$ is reachable from a free cell $x$ if at least one of these conditions holds:
|
| 4 |
+
|
| 5 |
+
* $x$ and $y$ share a side; * there exists a free cell $z$ such that $z$ is reachable from $x$ and $y$ is reachable from $z$.
|
| 6 |
+
|
| 7 |
+
A connected region is a set of free cells of the grid such that all cells in it are reachable from one another, but adding any other free cell to the set violates this rule.
|
| 8 |
+
|
| 9 |
+
For example, consider the following layout, where white cells are free, and dark grey cells are blocked:
|
| 10 |
+
|
| 11 |
+

|
| 12 |
+
|
| 13 |
+
There are $3$ regions in it, denoted with red, green and blue color respectively:
|
| 14 |
+
|
| 15 |
+

|
| 16 |
+
|
| 17 |
+
The given grid contains at most $1$ connected region. Your task is to calculate the number of free cells meeting the following constraint:
|
| 18 |
+
|
| 19 |
+
* if this cell is blocked, the number of connected regions becomes exactly $3$.
|
| 20 |
+
|
| 21 |
+
The first line contains a single integer $t$ ($1 \le t \le 10^4$) — the number of test cases.
|
| 22 |
+
|
| 23 |
+
The first line of each test case contains a single integer $n$ ($1 \le n \le 2 \cdot 10^5$) — the number of columns.
|
| 24 |
+
|
| 25 |
+
The $i$-th of the next two lines contains a description of the $i$-th row of the grid — the string $s_i$, consisting of $n$ characters. Each character is either . (denoting a free cell) or x (denoting a blocked cell).
|
| 26 |
+
|
| 27 |
+
Additional constraint on the input:
|
| 28 |
+
|
| 29 |
+
* the given grid contains at most $1$ connected region; * the sum of $n$ over all test cases doesn't exceed $2 \cdot 10^5$.
|
| 30 |
+
|
| 31 |
+
For each test case, print a single integer — the number of cells such that the number of connected regions becomes $3$ if this cell is blocked.
|
| 32 |
+
|
| 33 |
+
In the first test case, if the cell $(1, 3)$ is blocked, the number of connected regions becomes $3$ (as shown in the picture from the statement).
|