Wrong answer for :"B- Rock and Lever" of Round 672

Revision en1, by AK_04, 2020-09-25 07:49:37

include

include

using namespace std; long long int setBitNumber(long long int n) { if (n == 0) return 0;

long long int msb = 0; 
n = n / 2; 
while (n != 0) { 
    n = n / 2; 
    msb++; 
} 

return (1 << msb);

} int main() { long int t; cin>>t; while(t--){ long long int n,i,cnt=0; cin>>n; long long int a[n],b[n],maxi=0,gcnt=0; for(i=0;i<n;i++) { cin>>a[i]; maxi=max(a[i],maxi); } long int p =setBitNumber(maxi); long int q=log(p)/log(2); if(p==1) {

}
for(int j=0;j<=(q);j++)
{
    for(i=0;i<n;i++)
    {
        if(a[i]>=p)
        {
            b[i]=1;
        }
        else
        {
            b[i]=0;
        }
        if(b[i]==1)
        {
            cnt++;
            a[i]=0;
        }

    }

    gcnt =gcnt + cnt*(cnt-1)/2;
    cnt=0;
    p=p/2;

}
cout<<gcnt<<endl;
}

} what is wrong in the code ?

Tags #problem b, round 672

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en1 English AK_04 2020-09-25 07:49:37 1209 Initial revision (published)