CF1063E.Lasers and Mirrors

NOI/NOI+/CTSC

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Oleg came to see the maze of mirrors. The maze is a nn by nn room in which each cell is either empty or contains a mirror connecting opposite corners of this cell. Mirrors in this maze reflect light in a perfect way, which causes the interesting visual effects and contributes to the loss of orientation in the maze.

Oleg is a person of curious nature, so he decided to install nn lasers facing internal of the maze on the south wall of the maze. On the north wall of the maze, Oleg installed nn receivers, also facing internal of the maze. Let's number lasers and receivers from west to east with distinct integers from 11 to nn. Each laser sends a beam of some specific kind and receiver with number aia_i should receive the beam sent from laser number ii. Since two lasers' beams can't come to the same receiver, these numbers form a permutation — each of the receiver numbers occurs exactly once.

You came to the maze together with Oleg. Help him to place the mirrors in the initially empty maze so that the maximum number of lasers' beams will come to the receivers they should. There are no mirrors outside the maze, so if the laser beam leaves the maze, it will not be able to go back.

奥列格来到一座镜子迷宫参观。这座迷宫是一个 n×nn \times n 的房间,其中每个格子要么为空,要么含有一面连接该格子对角的镜子。迷宫中的镜子能完美地反射光线,从而产生奇妙的视觉效果,并导致人在迷宫中迷失方向。

奥列格生性好奇,于是决定在迷宫南侧墙壁内侧安装 nn 个激光器;同时在北侧墙壁内侧安装 nn 个接收器。我们将激光器和接收器均从西至东编号,编号为互异的整数 11 至 nn。每个激光器发射一种特定类型的光束,而编号为 aia_i 的接收器应接收到第 ii 个激光器所发射的光束。由于两个激光器的光束不能到达同一个接收器,因此这些编号 a1,a2,…,ana_1, a_2, \dots, a_n 构成一个排列——即每个接收器编号恰好出现一次。

你与奥列格一同来到迷宫。请帮助他在初始为空的迷宫中放置镜子,使得尽可能多的激光器光束能够准确抵达其对应的目标接收器。迷宫外部没有镜子,因此若某束激光离开迷宫,则无法再返回。

输入格式

The first line contains a single integer nn (1≤n≤10001 \le n \le 1000) — the size of the maze.

The second line contains a permutation of nn integers aia_i (1≤ai≤n1 \le a_i \le n), where aia_i defines the number of the receiver, to which the beam from ii-th laser should come.

第一行包含一个整数 nn(1≤n≤10001 \le n \le 1000)—— 迷宫的大小。

第二行包含 nn 个整数 aia_i(1≤ai≤n1 \le a_i \le n)的一个排列,其中 aia_i 表示第 ii 个激光器发出的光束应到达的接收器编号。

输出格式

In the first line print the maximum possible number of laser beams, which can come to the receivers they should.

In the next nn lines of length nn print the arrangement of mirrors, causing such number of laser beams to come where they should. If the corresponding cell is empty, print ".", otherwise print "/" or "\", depending on the orientation of the mirror.

In your output north should be above, south should be below, and west and east should be on left and on the right respectively.

It is allowed for laser beams to come not to the receivers they correspond to, but they are not counted in the answer.

If there are multiple arrangements of mirrors leading to the optimal answer — print any of them.

第一行输出能够到达对应接收器的激光束的最大可能数量。

接下来的 nn 行,每行长度为 nn,输出实现该最大数量的镜子排布方案。若对应格子为空,输出 “.”;否则根据镜子朝向输出 “/” 或 “\”。

在你的输出中,北(North)应在上方,南(South)应在下方,西(West)和东(East)应分别位于左侧和右侧。

允许激光束未到达其对应的接收器,但此类情况不计入答案。

若存在多种镜子排布方案均可达到最优解,则输出任意一种即可。

输入输出样例

  • 输入#1

    4
    4 1 3 2

    输出#1

    3
    .\..
    \\..
    /../
    ...\

说明/提示

The picture illustrates the arrangements of the mirrors in the first example.

该图展示了第一个示例中镜子的排列方式。

输入解题思路,AI测评打分。不知道怎么写?

首页