#P6687. 论如何玩转 Excel 表格

论如何玩转 Excel 表格

Description

There is a 2×n2 \times n table, filled with the numbers 12×n1 \sim 2 \times n with no repetition and nothing missing. You may perform several operations. In each operation, you can choose a 2×22 \times 2 square area and then rotate it by 180°180\degree.

Given the current state and the target state, determine whether the target state can be reached. If it can, output the minimum number of operations.

Input Format

The first line contains a positive integer nn.

The next two lines each contain nn positive integers, describing the current state of the table.

The next two lines each contain nn positive integers, describing the target state of the table.

Output Format

If there is no solution, output one line dldsgay!!1.

Otherwise, output one integer, the minimum number of operations.

1
1
2
2
1

dldsgay!!1

2
1 2
3 4
4 3
2 1

1

2
1 2
3 4
1 2
4 3

dldsgay!!1

3
1 6 2
4 3 5
2 4 3
5 1 6

2

Hint

Subtasks

This problem uses bundled testdata.

For 100%100\% of the testdata: 1n1061 \leq n \leq 10^6.

This problem has 1010 subtasks. The score and constraints of each subtask are as follows:

Subtask 11 (11 point): It is guaranteed that the output must be dldsgay!!1.
Subtask 22 (11 point): It is guaranteed that the target state is the same as the current state.
Subtask 33 (44 points): n=1n = 1.
Subtask 44 (55 points): n=2n = 2.
Subtask 55 (1414 points): 1n201 \leq n \leq 20.
Subtask 66 (1919 points): 1n1001 \leq n \leq 100.
Subtask 77 (1919 points): 1n10001 \leq n \leq 1000.
Subtask 88 (88 points): It is guaranteed that the first row of the target state is 1n1 \sim n in order, and the second row is n+12nn + 1 \sim 2n in order.
Subtask 99 (1010 points): It is guaranteed that there is no unsolvable case.
Subtask 1010 (1919 points): No special constraints.

Translated by ChatGPT 5