CF 245D Restoring Table

来源:互联网 发布:北京医院网络文案招聘 编辑:程序博客网 时间:2024/05/02 23:21
D - Restoring Table
Time Limit:2000MS    Memory Limit:262144KB    64bit IO Format:%I64d & %I64u

Description

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 integersa1, a2, ..., an. He also wrote a square matrixb of size n × n. The element of matrixb that sits in the i-th row in the j-th column (we'll denote it asbij) equals:

  • the "bitwise AND" of numbers ai andaj (that is,bij = ai & aj), ifi ≠ j;
  • -1, if i = j.

Having written out matrix b, Polycarpus got very happy and wipeda 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 numbersa1, a2, ..., an, that he has removed from the board. Polycarpus doesn't like large numbers, so any number in the restored sequence mustn't exceed 109.

Input

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

Output

Print n non-negative integers a1, a2, ..., an(0 ≤ ai ≤ 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.

Sample Input

Input
1-1
Output
0 
Input
3-1 18 018 -1 00 0 -1
Output
18 18 0 
Input
4-1 128 128 128128 -1 148 160128 148 -1 128128 160 128 -1
Output
128 180 148 160 

Hint

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


题目大意:

让你构造一个序列a1, a2, a3....an,使其满住矩阵 bij = ai & aj; (i != j) bij = -1 (i == j)


-1 就不用管了,矩阵自身就满足,关键是根据矩阵求出序列。

先求序列的第一个数,第一个数只与第一行和第一列有关,由于对称性,我们只考虑行。

怎样才能构造出a1,试想 & 有什么性质,只有两个数二进制表示相同位全为1时这一位才为1.相当与有一个数 a & (一堆其他的数)= 矩阵第一行(i != j)这不是明摆着矩阵第一行

的每一个数,这个数的二进制表示如果在某位上是1,a在这一位也比需是1,且要满足这一行的所有的数,相当与 这一行 b11 | b12 | b13 | b14 ....... | b1n = a;


依次求出后输出。


#include <iostream>#include <string.h>#include <string>#include <algorithm>#include <cmath>#include <stack>#include <cstdio>#include <queue>#include <cstdlib>#define INF 99999999#define MAXN 105using namespace std;int c[MAXN][MAXN];int array[MAXN];void input(){    int n;    cin >> n;    for (int i = 0; i < n; i++)    {        int sum = 0;                for (int j = 0; j < n; j++)        {            scanf("%d", &c[i][j]);                        if (i == j)            {                continue;            }            sum |= c[i][j];        }        array[i] = sum;    }    for (int i = 0; i < n; i++)    {        cout << array[i];                if (i != n - 1)        {            cout << ' ';        }    }    cout << endl;}int main(){    input();    return 0;}




原创粉丝点击