gettting WA in round 618 C question — Anu has a function

Revision en3, by vohrab1896, 2020-02-17 06:15:37

Hey CF Community! I have done this question ( https://mirror.codeforces.com/contest/1300/problem/C ) using prefix and suffix arrays but getting WA. As explained in the editorial firstly I calculated prefix and suffix value (~a[0])&(~a[1])... for each location. Then multiplied by a[i] for each i. But, I am getting WA. Following is my code. Please feel free to help. Thanks.

include<bits/stdc++.h>

using namespace std;

define forn(i,l,r) for(int i=l;i<r;i++)

define fore(i,n) forn(i,0,n)

int a[100001]; int prefix[100001],suffix[100001]; int main() { int n;

cin>>n;

fore(i,n)
 cin>>a[i];

int ipos=0;

forn(i,0,n)
{
    if(i==0)
     prefix[0]=1073741823;
    else prefix[i]=prefix[i-1]&(~(a[i-1]));
}

for(int i=n-1;i>=0;i--)
{
    if(i==n-1)
       suffix[i]=1073741823;
    else suffix[i]=(~a[i+1])&(suffix[i+1]);
}
int max_val=INT_MIN;
for(int i=0;i<=n-1;i++)                                                                 
{
    if(a[i]&(prefix[i]&suffix[i])>max_val)
    {
       max_val=a[i]&(prefix[i]&suffix[i]);
       ipos=i;
    }
}
cout<<a[ipos];

fore(i,n)
    if( ipos!=i)
       cout<<" "<<a[i];

return 0;

}

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en3 English vohrab1896 2020-02-17 06:15:37 146
en2 English vohrab1896 2020-02-16 18:10:55 6 Tiny change: 'ks. \n\n\n#inc' -> 'ks. \n\n\n\n\n#inc'
en1 English vohrab1896 2020-02-16 18:09:42 1401 Initial revision (published)