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.
Fails on test case: 1 7 1 2 3 4 5 8 5
Expected: 13 Got: 9
PS:
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
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
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?
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.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".
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.