Hi,
In the latest Division 2 round, I submitted the hyperlinked code (276587089) for Problem B. The strategy was simply to create two arrays $$$A$$$ and $$$B$$$ of size $$$100$$$ each, initialise them with zeros and set $$$A[i]=1$$$ such that $$$l \le I \le r$$$; and analogously for the array $$$B$$$. Then, I would iterate through each position $$$p$$$ in $$$A$$$ and increment a counter whenever $$$B[p-1]=1$$$ or $$$B[p+1]=1$$$. Evidently, this method is prone to counting the same door twice, so I kept a set of pairs to eliminate duplicates. At the end, I simply printed the size of the set.
I ran the example tests on my machine, and it did produce the correct results. Alas, the website's C++20 compiler did not produce the same output my machine did. As you can see, CodeForces' compiler produced the following:
2
4
3
4
It is even more bizarre considering that the C++17 compiler produced a different result for the same code. However, my computer did produce valid outputs, as evidenced by that screenshot (I hope the upload will be clear):
Since the compiler repeatedly produced outputs contradicting mine, I had to go with a different approach for B.
What exactly went wrong? What could I do to prevent that problem from occurring in the future?
Thank you, Kind regards.
Auto comment: topic has been updated by Turkmeniscoldish (previous revision, new revision, compare).
You have it in this place
You're going beyond boundaries
you took 101 element but go to 102
Here is the corrected code link
Thank you for pointing out the error! I have also realised that my set may be empty, should Alice and Bob never be adjacent; thus printing a result of $$$0$$$ when it should at least be $$$1$$$. Thanks for your input, mate.