题目: https://codeforces.com/contest/1903/problem/B
思想:
其中2^30-1的二进制为1111111......
代码:
// Problem: B. StORage room
// Contest: Codeforces - Codeforces Round 912 (Div. 2)
// URL: https://codeforces.com/contest/1903/problem/B
// Memory Limit: 256 MB
// Time Limit: 2000 ms
//
// Powered by CP Editor (https://cpeditor.org)
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 2e3+5;
ll n,a[N][N];
ll f[N];
int main(){
ios::sync_with_stdio(false);
cin.tie(0),cout.tie(0);
int T;
cin>>T;
while(T--){
cin>>n;
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
cin>>a[i][j];
}
}
for(int i=1;i<=n;i++){
f[i]=pow(2,30)-1;
}
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
if(i!=j){
f[i]=(f[i]&a[i][j]);
}
}
}
bool flag=1;
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
if(i==j) continue;
if((f[i]|f[j])!=a[i][j]){
flag=false;
break;
}
}
}
if(flag==false){
cout<<"NO"<<"\n";
}
else{
cout<<"YES"<<"\n";
for(int i=1;i<=n;i++){
cout<<f[i]<<" ";
}
cout<<"\n";
}
}
return 0;
}
//1 11 10 101