CF411B.Multi-core Processor
普及/提高-
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
The research center Q has developed a new multi-core processor. The processor consists of n cores and has k cells of cache memory. Consider the work of this processor.
At each cycle each core of the processor gets one instruction: either do nothing, or the number of the memory cell (the core will write an information to the cell). After receiving the command, the core executes it immediately. Sometimes it happens that at one cycle, multiple cores try to write the information into a single cell. Unfortunately, the developers did not foresee the possibility of resolving conflicts between cores, so in this case there is a deadlock: all these cores and the corresponding memory cell are locked forever. Each of the locked cores ignores all further commands, and no core in the future will be able to record an information into the locked cell. If any of the cores tries to write an information into some locked cell, it is immediately locked.
The development team wants to explore the deadlock situation. Therefore, they need a program that will simulate the processor for a given set of instructions for each core within m cycles . You're lucky, this interesting work is entrusted to you. According to the instructions, during the m cycles define for each core the number of the cycle, during which it will become locked. It is believed that initially all cores and all memory cells are not locked.
研究机构 Q 开发了一款新型多核处理器。该处理器包含 n 个核心,以及 k 个缓存存储单元。现考察该处理器的运行过程。
在每一周期中,处理器的每个核心均接收一条指令:要么空操作(即不执行任何操作),要么指定一个存储单元编号(该核心将向该单元写入信息)。接收到指令后,核心立即执行该指令。有时会出现这样的情况:在同一周期内,多个核心试图向同一个存储单元写入信息。遗憾的是,开发人员未预见到核心间冲突的解决机制,因此此时将发生死锁:所有这些尝试写入同一单元的核心,以及该存储单元本身,将被永久锁定。每个被锁定的核心将忽略后续所有指令;此后,任何核心均无法再向已被锁定的存储单元写入信息。若某个核心试图向一个已被锁定的存储单元写入信息,则该核心将立即被锁定。
开发团队希望深入分析死锁情形,因此需要一个程序来模拟该处理器在给定的 m 个周期内、针对每个核心的一组指令下的运行过程。你很幸运,这项有趣的工作交由你来完成。根据指令,在 m 个周期内,需为每个核心确定其被锁定所在的周期编号。初始状态下,所有核心与所有存储单元均未被锁定。
输入格式
The first line contains three integers n, m, k (1 ≤ n, m, k ≤ 100). Then follow n lines describing instructions. The i-th line contains m integers: _x__i_1, _x__i_2, ..., x__im (0 ≤ x__ij ≤ k), where x__ij is the instruction that must be executed by the i-th core at the j-th cycle. If x__ij equals 0, then the corresponding instruction is «do nothing». But if x__ij is a number from 1 to k, then the corresponding instruction is «write information to the memory cell number x__ij».
We assume that the cores are numbered from 1 to n, the work cycles are numbered from 1 to m and the memory cells are numbered from 1 to k.
第一行包含三个整数 n、m、k(1≤n,m,k≤100)。接下来是 n 行,每行描述一组指令。第 i 行包含 m 个整数:xi1, xi2, …, xim(0≤xij≤k),其中 xij 表示第 i 个核心在第 j 个工作周期中需执行的指令。若 xij=0,则对应指令为「不执行任何操作」;若 xij 是 1 到 k 之间的某个整数,则对应指令为「将信息写入编号为 xij 的内存单元」。
我们假定核心编号为 1 至 n,工作周期编号为 1 至 m,内存单元编号为 1 至 k。
输出格式
Print n lines. In the i-th line print integer t__i. This number should be equal to 0 if the i-th core won't be locked, or it should be equal to the number of the cycle when this core will be locked.
输出 n 行。在第 i 行中输出整数 t__i。若第 i 个核心不会被锁定,则 t__i 应为 0;否则,t__i 应为该核心被锁定的周期编号。
输入输出样例
输入#1
4 3 5 1 0 0 1 0 2 2 3 1 3 2 0
输出#1
1 1 3 0
输入#2
3 2 2 1 2 1 2 2 2
输出#2
1 1 0
输入#3
1 1 1 0
输出#3
0
输入解题思路,AI测评打分。不知道怎么写?