Yesterday, I took part in Codeforces Deltix Round Spring 2021 [Div.1 + Div.2], and happened something incredible.
I solved out the problem D and pasted the pretest(37), but I failed the system test(36).
The two codes are almost the same. Though my algorithm is to solve the problem randomly, it shouldn't exit a the time of 1.6s. Is there something wrong with my original code, or is there anything else wrong with the platform?
Thanks.
Maybe because you are using random shuffle which could be different in both submissions
Auto comment: topic has been updated by CQXYM (previous revision, new revision, compare).
From some research I did, clock() is platform dependent and in Linux, you will get CPU time, while on Windows you will get wall time.
CPU time, in short, is the time spent by the CPU on your program. On the other hand, wall time is the time spent in total(which can involve time spent by the CPU to start executing your program/waiting for executing your program).
Sources
https://levelup.gitconnected.com/8-ways-to-measure-execution-time-in-c-c-48634458d0f9
https://stackoverflow.com/questions/7335920/what-specifically-are-wall-clock-time-user-cpu-time-and-system-cpu-time-in-uni
Edit- Looks like codeforces runs under window OS, which mean the time you are getting using
clock()
is walltime which isn't necessarily the execution time, and could have extra things like the time your program waits for it's turn to be executed on the CPU.Source for my claim above https://mirror.codeforces.com/blog/entry/4088
Thanks. I got it, but how can I avoid these kind of problems?
You're using
random_shuffle
which is not determinant and depended onstd::rand
which returns random number in[0; RAND_MAX]
which is small (not guaranteed but I don't know any otger value than 32767.So you most likely shuffle only small part of vector.
Use
shuffle
instead