### HighHopes's blog

By HighHopes, history, 9 months ago,

Yesterday, I was stress testing the solution of problem E of some random participants from recent Div 3, with my solution but i couldn't hack them. After a few hours, two solutions which i stress tested got hacked but my stress testing couldn't catch where their solution was failing.
So, how do people find such a test cases to hack other's solution? Any suggestions are appreciated. Thank you.

• +17

 » 9 months ago, # |   0 Auto comment: topic has been updated by Baap_bakchod (previous revision, new revision, compare).
 » 9 months ago, # | ← Rev. 2 →   +4 Well. It depends on how you stressed tested those solutions of course.Finding a counterexample depends on what you want to pinpoint (i.e. a WA or TLE or maybe a RTE).If you want to cause TLE, perhaps you would like to analyze the time complexity of their code or even target the data structures that they are using (like unordered map).If you want to cause WA, you would want to find flaws in their logic rather than simply throwing random cases. For example, off by one bugs, special cases, etc.TLDR: The number of conditions that can be exercised in a typical program code on Codeforces is at least exponential. You won't get far if all you rely on is blind fuzzing.
 » 9 months ago, # |   0 I think they try proving the correctness of the target solution. Proving correctness != running it on random tests. If the proof fails somewhere, they can then proceed to hack the solution. After 1-3 hacks, they find some cases that majority of low ranked coders are overlooking.Stress Testing might help with TLE, but if you carefully read the target solution, you can estimate its time complexity and try to generate a case that will lead the solution towards its worst case time complexity.
 » 9 months ago, # |   0 How random are your generated random numbers are?
•  » » 9 months ago, # ^ |   +3 This#include "bits/stdc++.h" using namespace std; int rand(int l, int r){ static std::mt19937 rng(std::chrono::steady_clock::now().time_since_epoch().count()); std::uniform_int_distribution uid(l, r); return uid(rng); } int main() { srand(chrono::steady_clock::now().time_since_epoch().count()); int n = rand(1, 1e5); cout << n << '\n'; for (int i = 1; i <= n; ++i) { cout << rand(1, n) << ' '; } }