#P15128. [ROIR 2026] 跛脚国王

    ID: 17039 远端评测题 1000ms 512MiB 尝试: 0 已通过: 0 显示难度提高 上传者: 标签>Special Judge2026ROIR(俄罗斯)

[ROIR 2026] 跛脚国王

Problem Description

The Lame King moves on an n×mn \times m chessboard. Each move goes from the current cell to an edge-adjacent cell. We use (x,y)(x, y) to denote the cell in row xx and column yy.

The Lame King must visit all cells, passing through each cell exactly once, and return to the starting cell. Meanwhile, two edge-adjacent cells are marked on the board: (x1,y1)(x_1, y_1) and (x2,y2)(x_2, y_2). In the king’s traversal path, the cells (x1,y1)(x_1, y_1) and (x2,y2)(x_2, y_2) must appear consecutively: after the king reaches one of them, it must immediately move to the other.

Find a traversal order that satisfies the conditions, or determine that no such order exists.

Input Format

The first line contains two integers nn and mm (2≤n,m≤10002 \le n, m \le 1000), the size of the board.

The second line contains four integers x1x_1, y1y_1, x2x_2, y2y_2, the coordinates of two edge-adjacent cells (1≤x1,x2≤n1 \le x_1, x_2 \le n; 1≤y1,y2≤m1 \le y_1, y_2 \le m; ∣x1−x2∣+∣y1−y2∣=1|x_1-x_2|+|y_1-y_2|=1).

Output Format

If no such traversal path exists, output a single integer −1-1.

Otherwise, output n×m+1n \times m + 1 pairs of integers, the cell coordinates in traversal order. The starting cell should be output once at the beginning and once at the end.

4 3
2 2 3 2
1 1
2 1
2 2
3 2
3 1
4 1
4 2
4 3
3 3
2 3
1 3
1 2
1 1
3 5
1 2 2 2
-1

Hint

Sample Explanation

The diagram shows the traversal path for the first sample.

:::align{center} :::

Scoring Rules

This problem has 50 test points. Each test point is scored independently and is worth 2 points.

During the contest, you will be able to see the judging result for each test point.

Translation completed by DeepSeek.

Translated by ChatGPT 5