P27615 [洛谷] [Language Month Competition 202405] Luggage Placement
普及-
题目描述

Problem Description

Xiao S pushes her suitcase onto the high-speed train, embarking on an exciting journey.

The luggage rack in this carriage is divided into two columns, each with \( n \) positions, numbered from 1 to \( n \) sequentially from front to back. For any two positions numbered \( i \) and \( j \) (regardless of which column), the distance between them is \( \vert i - j \vert \).

\( \vert x \vert \) represents the absolute value of \( x \). When \( x \geq 0 \), \( \vert x \vert = x \); when \( x < 0 \), \( \vert x \vert = -x \).

Use \( 0 \) to denote the left column and \( 1 \) to denote the right column. Xiao S's seat is in the column \( p \) at position \( q \) (where \( p = 0 \) or \( 1 \), and \( 1 \leq q \leq n \)).

Now, Xiao S wants to place her suitcase in a certain position. However, some positions are already occupied by other luggage, so those positions cannot be used. Xiao S can only choose an empty position.

On this basis, Xiao S first hopes that the suitcase's placement position is as close to her as possible. Secondly, if there are two empty positions in different columns that are equidistant from her, Xiao S will choose the one in the same column as her.

Given the luggage placement situation in both columns, please find a position that meets the conditions. If there are no empty positions, output \( -1 \).

Input Format

The first line contains an integer \( n \), indicating the number of positions in each column.
The second line contains \( n \) integers, either \( 0 \) or \( 1 \), where the \( i \)-th integer indicates whether the \( i \)-th position in the left column is occupied by luggage (1 if occupied, 0 if not).
The third line contains \( n \) integers, either \( 0 \) or \( 1 \), where the \( i \)-th integer indicates whether the \( i \)-th position in the right column is occupied by luggage (1 if occupied, 0 if not).

The fourth line contains two integers \( p \) and \( q \), indicating which column Xiao S is in and the position within that column.

Output Format

Output one line. If there is a position to place the suitcase, output two integers, indicating whether the best position is in the left or right column and the distance from Xiao S's position.

If there is no position to place the suitcase, output the integer \( -1 \).

Sample Input and Output

Sample Input #1

5
0 1 1 1 1
1 0 1 1 1
0 3

Sample Output #1

1 1

Sample Input #2

5
0 1 1 1 1
0 1 1 1 1
0 3

Sample Output #2

0 2

Sample Input #3

5
1 1 1 1 1
1 1 1 1 1
0 3

Sample Output #3

-1

Notes

Sample 1 Explanation

For convenience, we use $\textcolor{green}{green}$ to represent empty positions without luggage and $\textcolor{red}{red}$ to represent positions with luggage.

Sample 1 is illustrated as follows:

Since the second position in the right column is closer to Xiao S, the best position is the second position in the right column, and the answer is 1 1 (indicating the position is in the right column, and the distance from Xiao S is 1).

Sample 2 Explanation

Sample 2 is illustrated as follows:

Since both positions are equidistant from Xiao S, and the left column position is in the same column as Xiao S, the answer is 0 2 (indicating the position is in the left column, and the distance from Xiao S is 2).

Sample 3 Explanation

Since there are no empty positions, the output is -1.

Data Range

For the first 30% of the data, it is guaranteed that Xiao S is in the left column, and all positions in the left column are occupied by luggage.
For the next 30% of the data, it is guaranteed that there is exactly one empty position in the left column and exactly one empty position in the right column.
For 100% of the data, it is guaranteed that \( 1 \leq q \leq n \leq 10^6 \), \( p \) is either 0 or 1, and the integers read in the second and third lines are either 0 or 1.

输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
5 0 1 1 1 1 1 0 1 1 1 0 3
样例输出
1 1