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.

Full text and comments »

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