-
Notifications
You must be signed in to change notification settings - Fork 160
/
Copy path1903B-StORageRoom.cpp
39 lines (34 loc) · 1.01 KB
/
1903B-StORageRoom.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include <cstdio>
#include <vector>
typedef long long ll;
int main(){
ll t; scanf("%lld", &t);
while(t--){
ll n; scanf("%lld", &n);
std::vector<std::vector<ll> > M(n, std::vector<ll>(n, 0));
std::vector<ll> a(n, 0);
for(ll row = 0; row < n; row++){
ll tmp((1LL << 30) - 1); //2^31 - 1
for(ll col = 0; col < n; col++){
ll x; scanf("%lld", &x);
M[row][col] = x;
if(col == row){continue;}
tmp = tmp & x;
}
a[row] = tmp;
}
bool possible(true);
for(ll row = 0; possible && row < n; row++){
for(ll col = 0; possible && col < n; col++){
if(row == col){continue;}
if((a[row] | a[col]) != M[row][col]){possible = false;}
}
}
if(possible){
puts("YES");
for(ll p = 0; p < n; p++){printf("%lld ", a[p]);}
puts("");
}
else{puts("NO");}
}
}