Neev4321's blog

By Neev4321, history, 6 weeks ago, In English

In this problem, my solution (code starts at line 71) is getting Wrong Answer.
I read the editorial.
My solution is the same as the editorial but without binary search.
I wrote a stress test which compared my solution with the editorialists code.
Using large T for different values of N, I could find no case where my answer was different.

stress test code

I cannot find any mistake in my logic or implementation.
Any help would be appreciated.

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

»
6 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

Fails on test case: 1 7 1 2 3 4 5 8 5

Expected: 13 Got: 9

PS:

  1. Is this your code? Looks like a poorly copied code or poorly copied idea from Editorial and coding it specially the lines inside if and checking DP

  2. You can refer to my code here. It uses the same idea as yours but instead of manually checking, I used rangePattern sum which is from this start to this end I want the pattern to match for all bits and used DP to make it faster. You can use SOS DP or trie as well

  • »
    »
    6 weeks ago, # ^ |
      Vote: I like it 0 Vote: I do not like it
    1. Yes, this is my in contest submission.
    2. I am aware of the different ways to solve this but I was looking to fix the mistake in my way (which I believe is the most efficient way possible).

    Good news, I fixed the bug (which was a missing "-1") and it got Accepted!
    PS: Why does my code look like it was copied?

    • »
      »
      »
      6 weeks ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      Congratulations. I also got AC using your code just now XD. Apologies for the PS-1, let's say, I saw this pattern vector<pair<ll, ll>> bits(60); and few more somewhere(wink). People can have similar code block and names but usually like what are the odds. Still my bad for misjudging.

      • »
        »
        »
        »
        6 weeks ago, # ^ |
          Vote: I like it 0 Vote: I do not like it

        No problem.
        By the way, in your code, you used #define int long long;
        It invokes undefined behaviour.
        Read "Reserved Macro names" on this website (int is a keyword).

        "A translation unit that uses any part of the standard library is not allowed to #define or #undef names lexically identical to ... keywords ... Otherwise, the behavior is undefined".

        • »
          »
          »
          »
          »
          6 weeks ago, # ^ |
          Rev. 2   Vote: I like it 0 Vote: I do not like it

          Interesting. I am aware about undefined behavior or rather I'm actually familiar with bad behavior but never came across any. Do you have any example where #define int long long resulted in an anomaly(not production code, in cp codes).

          EDIT: We should have this as personal chat and not as a blog. Other people might be getting this in "Recent Actions" which is unnecessary and does not add any value.