Codeforces Round 912 (Div. 2) 1903 B - StORage room Solution


 

 Problem Link :  https://codeforces.com/contest/1903/problem/B

Solution in C++:

  1. /// Author : AH_Tonmoy
  2. #include <bits/stdc++.h>
  3. using namespace std;
  4. int32_t main() {
  5. ios_base::sync_with_stdio(0);
  6. cin.tie(0);
  7. int t;
  8. cin >> t;
  9. while (t--) {
  10. int n ; cin >> n ;
  11. int a[n+1][n+1] ;
  12. vector<int>result;
  13. for ( int i = 0 ; i < n ; i++){
  14. int pre_and_value = 1073741823 ; // 2^30 - 1
  15. for ( int j = 0 ; j < n ; j++){
  16. cin >> a[i][j] ;
  17. if ( i == j ) continue ; // skip
  18. pre_and_value &= a[i][j] ;
  19. }
  20. result.push_back(pre_and_value) ;
  21. }
  22. bool ok = false ;
  23. for ( int i = 0 ; i < n ; i++){
  24. for ( int j = 0 ; j < n ; j++){
  25. if ( i == j ) continue ; // skip ;
  26. if (a[i][j] != ( result[i] | result[j])){ // condition check
  27. ok = true ;
  28. cout <<"NO\n";
  29. break ;
  30. }
  31. }
  32. if ( ok ) break ;
  33. }
  34. if(!ok){
  35. cout <<"YES\n" ;
  36. for (auto i : result){
  37. cout << i <<" ";
  38. }
  39. }
  40. }
  41. return 0 ;
  42. }

No comments

Most View Post

Recent post

Codeforces Round 925 (Div. 3) 1931D. Divisible Pairs Solution

    Problem Link  :   https://codeforces.com/contest/1931/problem/D S olution in C++: /// Author : AH_Tonmoy #include < bits / stdc ++. ...

Powered by Blogger.