CF1320F.Blocks and Sensors
NOI/NOI+/CTSC
通过率:0%
时间限制:3.00s
内存限制:512MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Polycarp plays a well-known computer game (we won't mention its name). Every object in this game consists of three-dimensional blocks — axis-aligned cubes of size 1×1×1. These blocks are unaffected by gravity, so they can float in the air without support. The blocks are placed in cells of size 1×1×1; each cell either contains exactly one block or is empty. Each cell is represented by its coordinates (x,y,z) (the cell with these coordinates is a cube with opposite corners in (x,y,z) and (x+1,y+1,z+1)) and its contents ax,y,z; if the cell is empty, then ax,y,z=0, otherwise ax,y,z is equal to the type of the block placed in it (the types are integers from 1 to 2⋅105).
Polycarp has built a large structure consisting of blocks. This structure can be enclosed in an axis-aligned rectangular parallelepiped of size n×m×k, containing all cells (x,y,z) such that x∈[1,n], y∈[1,m], and z∈[1,k]. After that, Polycarp has installed 2nm+2nk+2mk sensors around this parallelepiped. A sensor is a special block that sends a ray in some direction and shows the type of the first block that was hit by this ray (except for other sensors). The sensors installed by Polycarp are adjacent to the borders of the parallelepiped, and the rays sent by them are parallel to one of the coordinate axes and directed inside the parallelepiped. More formally, the sensors can be divided into 6 types:
- there are mk sensors of the first type; each such sensor is installed in (0,y,z), where y∈[1,m] and z∈[1,k], and it sends a ray that is parallel to the Ox axis and has the same direction;
- there are mk sensors of the second type; each such sensor is installed in (n+1,y,z), where y∈[1,m] and z∈[1,k], and it sends a ray that is parallel to the Ox axis and has the opposite direction;
- there are nk sensors of the third type; each such sensor is installed in (x,0,z), where x∈[1,n] and z∈[1,k], and it sends a ray that is parallel to the Oy axis and has the same direction;
- there are nk sensors of the fourth type; each such sensor is installed in (x,m+1,z), where x∈[1,n] and z∈[1,k], and it sends a ray that is parallel to the Oy axis and has the opposite direction;
- there are nm sensors of the fifth type; each such sensor is installed in (x,y,0), where x∈[1,n] and y∈[1,m], and it sends a ray that is parallel to the Oz axis and has the same direction;
- finally, there are nm sensors of the sixth type; each such sensor is installed in (x,y,k+1), where x∈[1,n] and y∈[1,m], and it sends a ray that is parallel to the Oz axis and has the opposite direction.
Polycarp has invited his friend Monocarp to play with him. Of course, as soon as Monocarp saw a large parallelepiped bounded by sensor blocks, he began to wonder what was inside of it. Polycarp didn't want to tell Monocarp the exact shape of the figure, so he provided Monocarp with the data from all sensors and told him to try guessing the contents of the parallelepiped by himself.
After some hours of thinking, Monocarp has no clue about what's inside the sensor-bounded space. But he does not want to give up, so he decided to ask for help. Can you write a program that will analyze the sensor data and construct any figure that is consistent with it?
Polycarp 玩一款广为人知的电脑游戏(我们不会透露其名称)。该游戏中的每个物体均由三维方块构成——即与坐标轴对齐、边长为 1×1×1 的立方体。这些方块不受重力影响,因此可在空中自由悬浮而无需支撑。方块被放置在大小为 1×1×1 的单元格中;每个单元格要么恰好包含一个方块,要么为空。每个单元格由其坐标 (x,y,z) 表示(该坐标对应的单元格是顶点分别为 (x,y,z) 和 (x+1,y+1,z+1) 的立方体),以及其内容 ax,y,z 表示;若单元格为空,则 ax,y,z=0;否则 ax,y,z 等于该单元格中方块的类型(类型为 1 到 2⋅105 之间的整数)。
Polycarp 构建了一个由方块组成的大型结构。该结构可被一个与坐标轴对齐的长方体(矩形平行六面体)完全包围,其尺寸为 n×m×k,覆盖所有满足 x∈[1,n]、y∈[1,m]、z∈[1,k] 的单元格 (x,y,z)。随后,Polycarp 在该长方体周围共安装了 2nm+2nk+2mk 个传感器。传感器是一种特殊方块,它沿某一方向发射一条射线,并显示该射线所碰到的第一个方块的类型(传感器自身除外)。Polycarp 安装的传感器均紧邻该长方体的边界,且其所发射的射线均平行于某一条坐标轴,并指向长方体内部。更准确地说,这些传感器可分为以下 6 类:
- 第一类传感器共 mk 个:每个传感器安装在位置 (0,y,z),其中 y∈[1,m]、z∈[1,k],并沿 Ox 轴正方向发射一条平行于 Ox 轴的射线;
- 第二类传感器共 mk 个:每个传感器安装在位置 (n+1,y,z),其中 y∈[1,m]、z∈[1,k],并沿 Ox 轴负方向发射一条平行于 Ox 轴的射线;
- 第三类传感器共 nk 个:每个传感器安装在位置 (x,0,z),其中 x∈[1,n]、z∈[1,k],并沿 Oy 轴正方向发射一条平行于 Oy 轴的射线;
- 第四类传感器共 nk 个:每个传感器安装在位置 (x,m+1,z),其中 x∈[1,n]、z∈[1,k],并沿 Oy 轴负方向发射一条平行于 Oy 轴的射线;
- 第五类传感器共 nm 个:每个传感器安装在位置 (x,y,0),其中 x∈[1,n]、y∈[1,m],并沿 Oz 轴正方向发射一条平行于 Oz 轴的射线;
- 第六类传感器共 nm 个:每个传感器安装在位置 (x,y,k+1),其中 x∈[1,n]、y∈[1,m],并沿 Oz 轴负方向发射一条平行于 Oz 轴的射线。
Polycarp 邀请了他的朋友 Monocarp 一起游玩。当然,Monocarp 一看到这个被传感器方块围成的巨大长方体,便立刻好奇其内部究竟是什么。Polycarp 不愿直接告诉 Monocarp 该物体的确切形状,于是他将全部传感器的数据提供给 Monocarp,并让他自行推断长方体内部的内容。
经过数小时思考,Monocarp 仍对传感器围成的空间内部一无所知。但他不愿放弃,因此决定求助于他人。你能编写一个程序,分析传感器数据,并构造出任意一个与之相符的内部结构吗?
输入格式
The first line contains three integers n, m and k (1≤n,m,k≤2⋅105, nmk≤2⋅105) — the dimensions of the parallelepiped.
Then the sensor data follows. For each sensor, its data is either 0, if the ray emitted from it reaches the opposite sensor (there are no blocks in between), or an integer from 1 to 2⋅105 denoting the type of the first block hit by the ray. The data is divided into 6 sections (one for each type of sensors), each consecutive pair of sections is separated by a blank line, and the first section is separated by a blank line from the first line of the input.
The first section consists of m lines containing k integers each. The j-th integer in the i-th line is the data from the sensor installed in (0,i,j).
The second section consists of m lines containing k integers each. The j-th integer in the i-th line is the data from the sensor installed in (n+1,i,j).
The third section consists of n lines containing k integers each. The j-th integer in the i-th line is the data from the sensor installed in (i,0,j).
The fourth section consists of n lines containing k integers each. The j-th integer in the i-th line is the data from the sensor installed in (i,m+1,j).
The fifth section consists of n lines containing m integers each. The j-th integer in the i-th line is the data from the sensor installed in (i,j,0).
Finally, the sixth section consists of n lines containing m integers each. The j-th integer in the i-th line is the data from the sensor installed in (i,j,k+1).
第一行包含三个整数 n、m 和 k(1≤n,m,k≤2⋅105,且 nmk≤2⋅105)——表示平行六面体的尺寸。
随后是传感器数据。对每个传感器,其数据为 0,表示从该传感器发出的射线到达了对面的传感器(中间无任何障碍物);否则为一个介于 1 到 2⋅105 之间的整数,表示该射线首次击中的障碍物类型。数据分为 6 个部分(每种传感器类型对应一个部分),相邻两个部分之间用一个空行分隔,且第一个部分与输入的第一行之间也用一个空行分隔。
第一部分包含 m 行,每行含 k 个整数。第 i 行的第 j 个整数表示安装在位置 (0,i,j) 的传感器所采集的数据。
第二部分包含 m 行,每行含 k 个整数。第 i 行的第 j 个整数表示安装在位置 (n+1,i,j) 的传感器所采集的数据。
第三部分包含 n 行,每行含 k 个整数。第 i 行的第 j 个整数表示安装在位置 (i,0,j) 的传感器所采集的数据。
第四部分包含 n 行,每行含 k 个整数。第 i 行的第 j 个整数表示安装在位置 (i,m+1,j) 的传感器所采集的数据。
第五部分包含 n 行,每行含 m 个整数。第 i 行的第 j 个整数表示安装在位置 (i,j,0) 的传感器所采集的数据。
最后,第六部分包含 n 行,每行含 m 个整数。第 i 行的第 j 个整数表示安装在位置 (i,j,k+1) 的传感器所采集的数据。
输出格式
If the information from the input is inconsistent, print one integer −1.
Otherwise, print the figure inside the parallelepiped as follows. The output should consist of nmk integers: a1,1,1, a1,1,2, ..., a1,1,k, a1,2,1, ..., a1,2,k, ..., a1,m,k, a2,1,1, ..., an,m,k, where ai,j,k is the type of the block in (i,j,k), or 0 if there is no block there. If there are multiple figures consistent with sensor data, describe any of them.
For your convenience, the sample output is formatted as follows: there are n separate sections for blocks having x=1, x=2, ..., x=n; each section consists of m lines containing k integers each. Note that this type of output is acceptable, but you may print the integers with any other formatting instead (even all integers on the same line), only their order matters.
如果输入的信息存在矛盾,则输出一个整数 −1。
否则,按如下方式输出平行六面体内部的图形。输出应包含 nmk 个整数:a1,1,1、a1,1,2、…、a1,1,k、a1,2,1、…、a1,2,k、…、a1,m,k、a2,1,1、…、an,m,k,其中 ai,j,k 表示位置 (i,j,k) 处方块的类型;若该位置无方块,则为 0。若存在多个与传感器数据一致的图形,输出其中任意一个即可。
为便于理解,样例输出格式如下:共分为 n 个独立的部分,分别对应 x=1、x=2、…、x=n 的方块;每个部分包含 m 行,每行含 k 个整数。注意,此类输出格式是可接受的,但您也可采用其他任意格式输出这些整数(甚至可将所有整数放在同一行),只要其顺序正确即可。
输入输出样例
输入#1
4 3 2 1 4 3 2 6 5 1 4 3 2 6 7 1 4 1 4 0 0 0 7 6 5 6 5 0 0 0 7 1 3 6 1 3 6 0 0 0 0 0 7 4 3 5 4 2 5 0 0 0 0 0 7
输出#1
1 4 3 0 6 5 1 4 3 2 6 5 0 0 0 0 0 0 0 0 0 0 0 7
输入#2
1 1 1 0 0 0 0 0 0
输出#2
0
输入#3
1 1 1 0 0 1337 0 0 0
输出#3
-1
输入#4
1 1 1 1337 1337 1337 1337 1337 1337
输出#4
1337
输入解题思路,AI测评打分。不知道怎么写?