CF245D.Restoring Table

普及/提高-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Recently Polycarpus has learned the "bitwise AND" operation (which is also called "AND") of non-negative integers. Now he wants to demonstrate the school IT teacher his superb manipulation with the learned operation.

For that Polycarpus came to school a little earlier and wrote on the board a sequence of non-negative integers _a_1, _a_2, ..., a__n. He also wrote a square matrix b of size n × n. The element of matrix b that sits in the i-th row in the j-th column (we'll denote it as b__ij) equals:

  • the "bitwise AND" of numbers a__i and a__j (that is, b__ij = a__i & a__j), if i ≠ j;
  • -1, if i = j.

Having written out matrix b, Polycarpus got very happy and wiped a off the blackboard. But the thing is, the teacher will want this sequence to check whether Polycarpus' calculations were correct. Polycarus urgently needs to restore the removed sequence of integers, or else he won't prove that he can count correctly.

Help Polycarpus, given matrix b, restore the sequence of numbers _a_1, _a_2, ..., a__n, that he has removed from the board. Polycarpus doesn't like large numbers, so any number in the restored sequence mustn't exceed 109.

最近,Polycarpus 学习了非负整数的“按位与”(bitwise AND)运算(也简称为 AND)。现在,他想向学校的 IT 老师展示自己对这一新学运算的高超掌握能力。

为此,Polycarpus 提前一点来到学校,在黑板上写下了一个非负整数序列 a1, a2, …, ana_1,\ a_2,\ \dots,\ a_n。他还写下一个大小为 n×nn \times n 的方阵 bb。矩阵 bb 中位于第 ii 行、第 jj 列的元素(记作 bijb_{ij})定义如下:

  • 若 i≠ji \ne j,则 bij=ai & ajb_{ij} = a_i\ \&\ a_j(即 aia_i 与 aja_j 的按位与);
  • 若 i=ji = j,则 bij=−1b_{ij} = -1。

写完矩阵 bb 后,Polycarpus 非常高兴,于是将原序列 aa 从黑板上擦掉了。但问题是,老师稍后会要求这个原始序列,以检验 Polycarpus 的计算是否正确。Polycarpus 必须紧急恢复被擦除的整数序列,否则就无法证明自己确实算得正确。

请帮助 Polycarpus:给定矩阵 bb,还原出他擦去的序列 a1, a2, …, ana_1,\ a_2,\ \dots,\ a_n。Polycarpus 不喜欢大数,因此还原出的任意一个数都不能超过 10910^9。

输入格式

The first line contains a single integer n (1 ≤ n ≤ 100) — the size of square matrix b. Next n lines contain matrix b. The i-th of these lines contains n space-separated integers: the j-th number represents the element of matrix b__ij. It is guaranteed, that for all i (1 ≤ i ≤ n) the following condition fulfills: b__ii = -1. It is guaranteed that for all i, j (1 ≤ i, j ≤ n; i ≠ j) the following condition fulfills: 0 ≤ b__ij ≤ 109, b__ij = b__ji.

第一行包含一个整数 nn(1≤n≤1001 \leq n \leq 100)——方阵 bb 的大小。接下来的 nn 行描述矩阵 bb。其中第 ii 行包含 nn 个以空格分隔的整数:第 jj 个数表示矩阵元素 bijb_{ij}。保证对所有 ii(1≤i≤n1 \leq i \leq n)均满足:bii=−1b_{ii} = -1。还保证对所有 i,ji, j(1≤i,j≤n1 \leq i, j \leq n;i≠ji \neq j)均满足:0≤bij≤1090 \leq b_{ij} \leq 10^9,且 bij=bjib_{ij} = b_{ji}。

输出格式

Print n non-negative integers _a_1, _a_2, ..., a__n (0 ≤ a__i ≤ 109) — the sequence that Polycarpus wiped off the board. Separate the numbers by whitespaces.

It is guaranteed that there is sequence a that satisfies the problem conditions. If there are multiple such sequences, you are allowed to print any of them.

输出 n 个非负整数 _a_₁, _a_₂, ..., a__n(0 ≤ a__i ≤ 10⁹)——即 Polycarpus 从黑板上擦去的序列。各数字之间用空格分隔。

题目保证存在满足条件的序列 a。若存在多个满足条件的序列,输出任意一个即可。

输入输出样例

  • 输入#1

    1
    -1

    输出#1

    0
  • 输入#2

    3
    -1 18 0
    18 -1 0
    0 0 -1

    输出#2

    18 18 0
  • 输入#3

    4
    -1 128 128 128
    128 -1 148 160
    128 148 -1 128
    128 160 128 -1

    输出#3

    128 180 148 160

说明/提示

If you do not know what is the "bitwise AND" operation please read: http://en.wikipedia.org/wiki/Bitwise_operation.

如果你不了解“按位与”运算,请阅读:http://en.wikipedia.org/wiki/Bitwise_operation。

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

首页