adnanaziz / EPIJudge

EPI Judge - Preview Release
Other
2.83k stars 1.88k forks source link

EPIJudge failed to run C++ test 'count_inversions.exe' with MSVC on windows #220

Open spacelg opened 3 years ago

spacelg commented 3 years ago

Hi All,

Environment: VS 2019 + Windows Server 2016

EPIJudge failed to run C++ test 'count_inversions.exe' with MSVC on windows. It can be reproduced on latest version b736406 on master branch. Could you please help look at this issue?

Repro steps:

  1. git clone https://github.com/adnanaziz/EPIJudge F:\gitP\adnanaziz\EPIJudge
  2. cd F:\gitP\adnanaziz\EPIJudge\epi_judge_cpp_solutions && mkdir build_amd64
  3. cd build_amd64
  4. cmake -G "Visual Studio 16 2019" -A x64 -DCMAKE_SYSTEM_VERSION=10.0.18362.0 -DCMAKE_BUILD_TYPE=Release ..
  5. msbuild /m /p:Platform=x64 /p:Configuration=Release epi_judge_cpp_solutions.sln /t:Rebuild
  6. cd F:\gitP\adnanaziz\EPIJudge\epi_judge_cpp_solutions\build_amd64\Release
  7. .\count_inversions.exe

Error info: 1015_releae

spacelg commented 3 years ago

We can fix this test issue as below.

This function (in count_inversions.cc): int CountSubarrayInversions(int start, int finish, vector* A_ptr) {

has several function calls in one expression. Compiler is allowed to call those fuctions in any order. If you re-write the function like this:

int CountSubarrayInversions(int start, int finish, vector* A_ptr) { if (finish - start <= 1) { return 0; }

int mid = start + ((finish - start) / 2); int res = CountSubarrayInversions(start, mid, A_ptr); res += CountSubarrayInversions(mid, finish, A_ptr); res += MergeSortAndCountInversionsAcrossSubarrays(start, mid, finish, A_ptr);

return res; }

Test passes with optimizations.