TheDark_Knight's blog

By TheDark_Knight, history, 7 years ago, In English

Hey, I have been stuck at this problem for quite long 327E - Axis Walking. According to the editorial the author specified an approach involving "meet in the middle", but my implementation caused a TLE 76646016. Then he had mentioned that a bitmask DP approach of O(n*(2^n)) somehow unintentionally manages to pass the test cases & referenced to a particular submission 4017915. I had gone through the code but once again when implemented it caused a TLE. To figure out the reason behind this I tried to step by step make my code similar to the AC submission ( 4017915 ) mentioned in the editorial but again failed at the end with my submission as: 76648464.

Any kind of help would be appreciated.

Edit: This issue has been solved by converting all long long to int everywhere.

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

| Write comment?
»
7 years ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Try using fast input output

»
7 years ago, hide # |
 
Vote: I like it +8 Vote: I do not like it

I think it's because of using long long unnecessarily. Only your dp array needs to be long long. rest everything can be int and your code should pass.Try doing it.

»
7 years ago, hide # |
 
Vote: I like it +5 Vote: I do not like it

I submitted your code in C++17(64) and it passed in 2000ms

  • »
    »
    7 years ago, hide # ^ |
     
    Vote: I like it +3 Vote: I do not like it

    If this is the case then it seems really strange, any reason which you could figure out for this peculiar behaviour?

    • »
      »
      »
      7 years ago, hide # ^ |
      ← Rev. 3  
      Vote: I like it +5 Vote: I do not like it

      You uses right shift for long long, not for int. I just replaced by int and got accepted with 32-bit compiler too. Submission

      any reason

      $$$64/32=2$$$

      • »
        »
        »
        »
        7 years ago, hide # ^ |
         
        Vote: I like it 0 Vote: I do not like it

        Ya probably the 32 bit compiler implements the right shift operation for long long slower than the 64 bit compiler. Instead of calculating that value (i.e 1ll<<j) a lot of times I should had cached it in an array & that would indeed save a lot of time.

»
7 years ago, hide # |
 
Vote: I like it +5 Vote: I do not like it

I just changed some long long computations to int 76700036

»
7 years ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Auto comment: topic has been updated by TheDark_Knight (previous revision, new revision, compare).