Please read the new rule regarding the restriction on the use of AI tools. ×

I do not understand why the server's compiler produced outputs different to my own.

Revision en2, by Turkmeniscoldish, 2024-08-15 20:31:45

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.

Tags compiler, cpp, help

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en2 English Turkmeniscoldish 2024-08-15 20:31:45 347 Tiny change: 'nshot:\n\n' -> 'nshot:\n\n![ ](https://mirror.codeforces.com/442929/test.png)\n\n' (published)
en1 English Turkmeniscoldish 2024-08-15 20:27:44 1191 Initial revision (saved to drafts)