Блог пользователя vohrab1896

Автор vohrab1896, история, 5 лет назад, По-английски

Hey CF Community! I have done this question ( https://codeforces.net/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;

}

  • Проголосовать: нравится
  • -27
  • Проголосовать: не нравится