CF1903B.StORage room

普及-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

In Cyprus, the weather is pretty hot. Thus, Theofanis saw this as an opportunity to create an ice cream company.

He keeps the ice cream safe from other ice cream producers by locking it inside big storage rooms. However, he forgot the password. Luckily, the lock has a special feature for forgetful people!

It gives you a table MM with nn rows and nn columns of non-negative integers, and to open the lock, you need to find an array aa of nn elements such that:

  • 0≤ai<2300 \le a_i \lt 2^{30}, and
  • Mi,j=ai∣ajM_{i,j} = a_i | a_j for all i≠ji \neq j, where ∣| denotes the bitwise OR operation.

The lock has a bug, and sometimes it gives tables without any solutions. In that case, the ice cream will remain frozen for the rest of eternity.

Can you find an array to open the lock?

在塞浦路斯,天气非常炎热。因此,西奥法尼斯将此视为创办一家冰淇淋公司的良机。

他将冰淇淋锁在大型储藏室内,以防其他冰淇淋生产商窃取。然而,他忘记了密码。幸运的是,该锁具为健忘者设计了一项特殊功能!

它会提供一个 nn 行 nn 列的非负整数表格 MM;要打开锁,你需要找出一个包含 nn 个元素的数组 aa,使得:

  • 0≤ai<2300 \le a_i \lt 2^{30},且
  • 对所有 i≠ji \neq j,均有 Mi,j=ai∣ajM_{i,j} = a_i | a_j,其中 ∣| 表示按位或运算。

该锁存在一个缺陷:有时它给出的表格无解。此时,冰淇淋将永远冻结下去。

你能找到一个能打开锁的数组吗?

输入格式

The first line contains a single integer tt (1≤t≤1031 \le t \le 10^{3}) — the number of test cases.

The first line of each test case contains a single integer nn (1≤n≤1031 \le n \le 10^{3}) — the size of the hidden array.

The next nn lines describe the rows of MM, line ii contains the table values Mi,1,Mi,2,…,Mi,nM_{i,1}, M_{i,2}, \ldots, M_{i,n} (0≤Mi,j<2300 \le M_{i,j} \lt 2^{30}).

It is guaranteed that Mi,i=0M_{i,i} = 0 and Mi,j=Mj,iM_{i,j} = M_{j,i} for all 1≤i,j≤n1 \le i,j \le n.

It is also guaranteed that the sum of nn over all test cases does not exceed 10310^{3}.

第一行包含一个整数 tt(1≤t≤1031 \le t \le 10^{3})—— 测试用例的数量。

每个测试用例的第一行包含一个整数 nn(1≤n≤1031 \le n \le 10^{3})—— 隐藏数组的大小。

接下来的 nn 行描述矩阵 MM 的各行,其中第 ii 行包含表格值 Mi,1,Mi,2,…,Mi,nM_{i,1}, M_{i,2}, \ldots, M_{i,n}(0≤Mi,j<2300 \le M_{i,j} \lt 2^{30})。

保证对所有 1≤i,j≤n1 \le i,j \le n,均有 Mi,i=0M_{i,i} = 0 且 Mi,j=Mj,iM_{i,j} = M_{j,i}。

还保证所有测试用例的 nn 值之和不超过 10310^{3}。

输出格式

For each test case, if there is a solution print YES and an array that satisfies the property, otherwise print NO.

If there are multiple solutions, print any of them.

You can output the answer in any case (upper or lower). For example, the strings "yEs", "yes", "Yes", and "YES" will be recognized as positive responses.

对于每个测试用例,如果存在解,则输出 YES 和一个满足该性质的数组;否则输出 NO。

如果存在多个解,输出任意一个即可。

你可以以任意大小写形式输出答案(大写或小写均可)。例如,字符串 "yEs"、"yes"、"Yes" 和 "YES" 均会被识别为肯定回答。

输入输出样例

  • 输入#1

    4
    1
    0
    4
    0 3 3 5
    3 0 3 7
    3 3 0 7
    5 7 7 0
    5
    0 7 7 5 5
    7 0 3 2 6
    7 3 0 3 7
    5 2 3 0 4
    5 6 7 4 0
    3
    0 0 1
    0 0 0
    1 0 0

    输出#1

    YES
    7
    YES
    1 3 2 5 
    YES
    5 2 3 0 4
    NO

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

首页