A15630 | Koxia, Mahiru and Winter Festival
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Wow, what a big face!
Kagura Mahiru
Koxia and Mahiru are enjoying the Winter Festival. The streets of the Winter Festival can be represented as a $n \times n$ undirected grid graph. Formally, the set of vertices is $\{(i,j) \; | \; 1 \leq i,j\leq n \}$ and two vertices $(i_1,j_1)$ and $(i_2,j_2)$ are connected by an edge if and only if $|i_1-i_2|+|j_1-j_2|=1$ .
 A network with size $n = 3$ .Koxia and Mahiru are planning to visit The Winter Festival by traversing $2n$ routes. Although routes are not planned yet, the endpoints of the routes are already planned as follows:
- In the $i$ -th route, they want to start from vertex $(1, i)$ and end at vertex $(n, p_i)$ , where $p$ is a permutation of length $n$ .
- In the $(i+n)$ -th route, they want to start from vertex $(i, 1)$ and end at vertex $(q_i, n)$ , where $q$ is a permutation of length $n$ .
 A network with size $n = 3$ , points to be connected are shown in the same color for $p = [3, 2, 1]$ and $q = [3, 1, 2]$ .Your task is to find a routing scheme — $2n$ paths where each path connects the specified endpoints. Let's define the congestion of an edge as the number of times it is used (both directions combined) in the routing scheme. In order to ensure that Koxia and Mahiru won't get too bored because of traversing repeated edges, please find a routing scheme that minimizes the maximum congestion among all edges.
 An example solution — the maximum congestion is $2$ , which is optimal in this case.
Kagura Mahiru
Koxia and Mahiru are enjoying the Winter Festival. The streets of the Winter Festival can be represented as a $n \times n$ undirected grid graph. Formally, the set of vertices is $\{(i,j) \; | \; 1 \leq i,j\leq n \}$ and two vertices $(i_1,j_1)$ and $(i_2,j_2)$ are connected by an edge if and only if $|i_1-i_2|+|j_1-j_2|=1$ .
 A network with size $n = 3$ .Koxia and Mahiru are planning to visit The Winter Festival by traversing $2n$ routes. Although routes are not planned yet, the endpoints of the routes are already planned as follows:
- In the $i$ -th route, they want to start from vertex $(1, i)$ and end at vertex $(n, p_i)$ , where $p$ is a permutation of length $n$ .
- In the $(i+n)$ -th route, they want to start from vertex $(i, 1)$ and end at vertex $(q_i, n)$ , where $q$ is a permutation of length $n$ .
 A network with size $n = 3$ , points to be connected are shown in the same color for $p = [3, 2, 1]$ and $q = [3, 1, 2]$ .Your task is to find a routing scheme — $2n$ paths where each path connects the specified endpoints. Let's define the congestion of an edge as the number of times it is used (both directions combined) in the routing scheme. In order to ensure that Koxia and Mahiru won't get too bored because of traversing repeated edges, please find a routing scheme that minimizes the maximum congestion among all edges.
 An example solution — the maximum congestion is $2$ , which is optimal in this case.
输入格式
The first line contains an integer $n$ ( $2 \leq n \leq 200$ ) — the size of the network.
The second line contains $n$ integers $p_1, p_2, \dots, p_n$ ( $1 \leq p_i \leq n$ ).
The third line contains $n$ integers $q_1, q_2, \dots, q_n$ ( $1 \leq q_i \leq n$ ).
It is guaranteed that both $p$ and $q$ are permutations of length $n$ .
The second line contains $n$ integers $p_1, p_2, \dots, p_n$ ( $1 \leq p_i \leq n$ ).
The third line contains $n$ integers $q_1, q_2, \dots, q_n$ ( $1 \leq q_i \leq n$ ).
It is guaranteed that both $p$ and $q$ are permutations of length $n$ .
输出格式
Output $2n$ lines, each line describing a route.
The first $n$ lines should describe the connections from top to bottom. The $i$ -th line should describe the route starting at vertex $(1, i)$ and ending at vertex $(n, p_i)$ .
The next $n$ lines should describe the connections from left to right. The $(i+n)$ -th line should describe the route starting at vertex $(i, 1)$ and ending at vertex $(q_i, n)$ .
Each line describing a route should start with an integer $k$ ( $2 \le k \le 10^5$ ) — the number of vertices the route passes, including the starting and ending vertices. Then output all the vertices on the route in order. In other words, if the route is $(x_1, y_1) \rightarrow (x_2, y_2) \rightarrow \dots \rightarrow (x_k, y_k)$ , then output $k~x_1~y_1~x_2~y_2 \ldots x_k~y_k$ . Note that $|x_i-x_{i+1}|+|y_i-y_{i+1}| = 1$ should holds for $1 \le i < k$ .
If there are multiple solutions that minimize the maximum congestion, you may output any.
The first $n$ lines should describe the connections from top to bottom. The $i$ -th line should describe the route starting at vertex $(1, i)$ and ending at vertex $(n, p_i)$ .
The next $n$ lines should describe the connections from left to right. The $(i+n)$ -th line should describe the route starting at vertex $(i, 1)$ and ending at vertex $(q_i, n)$ .
Each line describing a route should start with an integer $k$ ( $2 \le k \le 10^5$ ) — the number of vertices the route passes, including the starting and ending vertices. Then output all the vertices on the route in order. In other words, if the route is $(x_1, y_1) \rightarrow (x_2, y_2) \rightarrow \dots \rightarrow (x_k, y_k)$ , then output $k~x_1~y_1~x_2~y_2 \ldots x_k~y_k$ . Note that $|x_i-x_{i+1}|+|y_i-y_{i+1}| = 1$ should holds for $1 \le i < k$ .
If there are multiple solutions that minimize the maximum congestion, you may output any.
输入输出样例
输入 #1
3 3 2 1 3 1 2
输出 #1
5 1 1 2 1 2 2 3 2 3 3 3 1 2 2 2 3 2 5 1 3 1 2 1 1 2 1 3 1 5 1 1 1 2 1 3 2 3 3 3 4 2 1 2 2 2 3 1 3 4 3 1 3 2 3 3 2 3
输入 #2
4 3 4 2 1 2 4 1 3
输出 #2
6 1 1 1 2 2 2 2 3 3 3 4 3 6 1 2 1 3 2 3 2 4 3 4 4 4 5 1 3 2 3 2 2 3 2 4 2 7 1 4 1 3 1 2 2 2 2 1 3 1 4 1 7 1 1 2 1 3 1 3 2 3 3 2 3 2 4 6 2 1 2 2 3 2 4 2 4 3 4 4 6 3 1 3 2 3 3 3 4 2 4 1 4 5 4 1 4 2 4 3 3 3 3 4
输入 #3
3 1 2 3 1 2 3
输出 #3
3 1 1 2 1 3 1 3 1 2 2 2 3 2 3 1 3 2 3 3 3 3 1 1 1 2 1 3 3 2 1 2 2 2 3 3 3 1 3 2 3 3
The first example corresponds to the figures in the problem statement.
The output for examples $2$ and $3$ respectively are visualized below:
 Sample output for examples $2$ and $3$ . Maximum congestions are $2$ and $1$ respectively.
The output for examples $2$ and $3$ respectively are visualized below:
 Sample output for examples $2$ and $3$ . Maximum congestions are $2$ and $1$ respectively.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted