OR-thodox Distinction Problem Code: ORTHODOX Solution Codechef

 #include <iostream>
#include <vector>
using namespace std;
int main(){
  ios::sync_with_stdio(0);
  cin.tie(NULL);
  int t;
  cin>>t;
  while(t--){
    int n;
    long long ans=0,cnt=0,tmp;
    cin>>n;
    vector<int> a(61);
    int zr=0;
    vector<long long> b(n);
    for(int i=0;i<n;i++){
      cin>>tmp;
      b[i]=tmp;
      if(tmp==0)zr=1;
      for(int j=0;j<61;j++){
        if(tmp&((long long)1<<j))
          a[j]++;
      }
    }
    int flag=0,tflag=0;
    for(int i=0;i<n;i++){
      tflag=0;
      tmp=b[i];
      for(int j=0;j<61;j++){
        if((tmp&((long long)1<<j))&&a[j]==1){tflag=1;}
      }
      if(!tflag){flag=1;break;}
    }
    if(n==1)flag=0;
    else if(zr) flag=1;
    if(flag)
      cout<<"NO";
    else
      cout<<"YES";
    cout<<'\n';
  }
  return 0;
}

Comments