Why False ???!!!!

Revision en2, by Yazdanra, 2018-02-13 16:43:27

Hi Codeforces !!! i before in contest see 916B - Jamie and Binary Sequence (changed after round) problem. and i tried for solve that. but this problem changed after round. :' (
my code for this problem is in 34328725 . and i sure this is true. :-) i hope you can help me for find bug of my code. but i sure it's true. ^_^

in part ( 1 ) i give input and check "NO" answer.

//

long long int n,k; cin>>n>>k;
if ( __builtin_popcount( n ) > k )
    return cout << "No\n" , 0 ;

//

in part ( 2 ) i get number n in binary

//

long long int  num = n ;
string bits = "" ;
while ( num > 0 ) {
    bits += to_string( num%2 ) ;
    num >>= 1 ;
}

//

in part ( 3 ) i save andis of one's in "bits" on the "vec"

//

vector < int > vec ;
for ( int i=0 ; i<(int)bits.size() ; i++ ) 
    if ( bits[i] == '1' ) vec.push_back( i ) ;

//

and in the last part : i delet 'x' ( element of vec ) and add "x-1" and "x-1" because : ( x << 1 ) = ( (x-1) << 1 ) + ( (x-1) << 1 ) while vec.size() < k

//

while ( sz(vec) > k ) {
    int x = vec.back() ;
    vec.pop_back() ;
    vec.push_back( x-1 ) ;
    vec.push_back( x-1 ) ;
}

sort( vec.begin() , vec.end() ) ;
reverse( vec.begin() , vec.end() ) ;
cout << "YES\n" ;
for ( auto e : vec )
    cout << e << ' ' ;
return cout << endl , 0 ;

//

and FINISH . ^_^

Tags 916b, bug, debug, help_me

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en2 English Yazdanra 2018-02-13 16:43:27 136
en1 English Yazdanra 2018-02-13 16:42:46 1586 Initial revision (published)