Codeforces Round 912 (Div. 2) 1903 B - StORage room Solution
Problem Link : https://codeforces.com/contest/1903/problem/B
Solution in C++:
- /// Author : AH_Tonmoy
- #include <bits/stdc++.h>
- using namespace std;
- int32_t main() {
- ios_base::sync_with_stdio(0);
- cin.tie(0);
- int t;
- cin >> t;
- while (t--) {
- int n ; cin >> n ;
- int a[n+1][n+1] ;
- vector<int>result;
- for ( int i = 0 ; i < n ; i++){
- int pre_and_value = 1073741823 ; // 2^30 - 1
- for ( int j = 0 ; j < n ; j++){
- cin >> a[i][j] ;
- if ( i == j ) continue ; // skip
- pre_and_value &= a[i][j] ;
- }
- result.push_back(pre_and_value) ;
- }
- bool ok = false ;
- for ( int i = 0 ; i < n ; i++){
- for ( int j = 0 ; j < n ; j++){
- if ( i == j ) continue ; // skip ;
- if (a[i][j] != ( result[i] | result[j])){ // condition check
- ok = true ;
- cout <<"NO\n";
- break ;
- }
- }
- if ( ok ) break ;
- }
- if(!ok){
- cout <<"YES\n" ;
- for (auto i : result){
- cout << i <<" ";
- }
- }
- }
- return 0 ;
- }
No comments