ORTHODOX - Editorial

Please link submissions that fail this test-case

Your code gives No if input is just one element - 0.

4 Likes

Didn’t expected that this will be done in O(n^2) … wasted 2 hours over thinking about optimized solution …
RIP ratings

18 Likes

no bro, i just checked, total pages of submission are 83, and pages for python submission are 4, so, rest 79 pages are for c++ or java or any other language.

Answer was just a google search away…
Please take case of this…

Link 1: https://www.geeksforgeeks.org/count-distinct-bitwise-or-of-all-subarrays/
Link 2: - LeetCode

anyone can just find the total distinct OR values of that array by this code:

and simply check if ((n*(n+1))/2) is equal to the above result or not. If its equal print yes. else no.

check out the soultion:
https://www.codechef.com/viewsolution/35817176

10 Likes

Tester code is superb , same like THIS

Link
There are many.

I have do this with another logic & this also accepted.

#include <stdio.h>
#include<math.h>

typedef long long int ll;

int cmpfunc(const void a,const void b){
if(
(ll
)a==(ll)b) return 0;
else if((ll)a>(ll)b) return 1;
else return -1;
}

int main()
{
int t,n,flag,l;
scanf("%d",&t);
while(t–)
{
scanf("%d",&n);
l=2*(n-1);
ll a[n],b[n],c[l],total=0,left=0,right=0;flag=1;
for(int i=0;i<n;i++)
{
scanf("%lld",&a[i]);
b[i]=a[i];
total|=a[i];
}
qsort(a,n,sizeof(ll),cmpfunc);
for(int i=1;i<n;i++)
{
if(a[i]==a[i-1])
{
printf(“NO\n”);
flag=0;
break;
}
}
if(flag)
{
for(int i=0;i<n-1;i++)c[(2i)]=(left|=b[i]);
for(int i=n-1;i>0;i–)c[(2
(i-1))+1]=(right|=b[i]);
qsort(c,l,sizeof(ll),cmpfunc);
for(int i=0;i<l;i++)
{
if((i!=0)&(c[i]==c[i-1])){flag=0;break;}
if(c[i]==total){flag=0;break;}
}
if(!flag)printf(“NO\n”);
else printf(“YES\n”);
}
}
}

Weak Test Case for ORTHODOX

Input:

1 
3
1 50 99

Output:

NO

I have seen Solutions where the Output is YES.
@admin

2 Likes

Bhai koi plz mujhe ye answer smjha dega, meko bilkul smjh nhi aaya ye answer.

Please bhaiyo.

Please format your code

Thank you very much.
After adding just one more if statement it got accepted.

Seriously , same. And then i just saw submissions rising like a missile. The gfg and leetcode makes sense now.

2 Likes

why the answer is no if N>62??

5 Likes

Yeah bro :slight_smile: this was pure hard luck :sob:

2 Likes

I don’t Understand I had done the same thing except this if (n >= 100) { cout << "NO\n";…I got Tle First then i had to rethink and this cost me 1.30 hours i could have been in top 1000 now i am in late 2000… that’s pathetic…

The complexity of this solution is O(n^2). So how is it getting accepted within one second? Is it due to weak test cases?
Someone please reply and clear this dilemma.

2 Likes

Along with the weak test cases, don’t you think time limit was a bit off? O(N^2) within one second, maybe they haven’t put the worst cases as the test case?

1 Like

Its n ^ 2 when n <= 62, otherwise it’s always a NO.
So for n <= 62, you can simply do brute force, won’t TLE.

1 Like

Many people who unable to solve ORTHODOX and after the contest they get to know, it’s already on google / net -

to setters -

Screenshot_2020-07-20 dil se bura lagta hai bhai - Google Search

21 Likes