Turkmeniscoldish's blog

By Turkmeniscoldish, history, 3 months ago, In English

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.

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

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

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

»
3 months ago, # |
  Vote: I like it +1 Vote: I do not like it

You have it in this place

 if(a[i] && b[i+1]) ans.insert({i, i+1});
 if(a[i] && b[i-1]) ans.insert({i-1, i});

You're going beyond boundaries

you took 101 element but go to 102

Here is the corrected code link

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

    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.