Codeforces celebrates 10 years! We are pleased to announce the crowdfunding-campaign. Congratulate us by the link https://codeforces.com/10years. ×

v-O_O-v's blog

By v-O_O-v, history, 10 months ago, In English,

Does anyone have a simpler approach of solving this problem? Please share with me.

 
 
 
 
  • Vote: I like it
  • -16
  • Vote: I do not like it

»
10 months ago, # |
  Vote: I like it 0 Vote: I do not like it

if u can understand python the refer to my solution https://codeforces.com/contest/1152/submission/53235674 starting from MSB following a greedy type appraoch

  • »
    »
    10 months ago, # ^ |
      Vote: I like it +2 Vote: I do not like it

    Can you explain your logic I have difficulty in reading python. Thanks!

    • »
      »
      »
      10 months ago, # ^ |
        Vote: I like it +1 Vote: I do not like it

      first of all i converted the number into its binary and then checked if all bits are set if not then i start traversing from the most significant bit if a bit is set then continue else i calculated the length of all the bits starting from that '0' bit and then xored it with the number(all bits set with the lenght i calculated) AND then checked if the number becomes 2^n-1 (break if yes) else continue till the number becomes 2^n-1 (till we reach the last bit). take an example and u will understand refering to my code

      • »
        »
        »
        »
        10 months ago, # ^ |
          Vote: I like it +1 Vote: I do not like it

        Thanks! Understood

      • »
        »
        »
        »
        10 months ago, # ^ |
          Vote: I like it 0 Vote: I do not like it

        your approach is intuitive, Thanks

      • »
        »
        »
        »
        10 months ago, # ^ |
          Vote: I like it 0 Vote: I do not like it

        can you find the mistake in my code? I am new to coding. Here is my solution,I got testcase 4 wrong!! solution

    • »
      »
      »
      10 months ago, # ^ |
        Vote: I like it +1 Vote: I do not like it

      sorry for the down vote by mistake:)

      • »
        »
        »
        »
        10 months ago, # ^ |
          Vote: I like it +1 Vote: I do not like it

        No problem. I don't care about those a question is a question l.

        • »
          »
          »
          »
          »
          10 months ago, # ^ |
            Vote: I like it +1 Vote: I do not like it

          I finally solved it using almost the same idea of yours. AC in 7 goes. my solution Thanks!.

»
10 months ago, # |
  Vote: I like it 0 Vote: I do not like it

Thanks for asking the doubt , my doubt is also cleared.