An old blog discussed about how to ac every problem. One comment from a certain user struck me. Instead of the usual ~10^{-6736}~ chance, I can make it ~100\%~ under some conditions.
Conditions
These following conditions must be met in order to guess, no, actually get the tests:
- Being allowed to submit as many times as you want.
- No batch grading.
- Ability to use binary search.
- Patience.
Proccess
There is one trick I would like to introduce to you: the Kim Jong Un trick.
Code:
void nuke(){
while (1){}
}
How does this work?
When you call the ~nuke()~ function, your code automatically gets TLE (Time Limit Exceeded).
So how do we use this to our advantage?
For instance, the input is only a positive integer ~n~ ~(1 \le n \le 1000)~. What you are going to do is binary search on ~n~. First, you set the left bound ~l~ to 1, and the right bound ~r~ to ~1000~. You set ~mid~ to ~(l + r)/2~. You read ~n~ from the input, check:
- If ~n < mid~, call the ~nuke()~ function.
- Else, don't call the function.
After that, submit your code and check if it gets TLE. If it does, it means that ~n < mid~, and you should set the right bound to ~mid - 1~, if it doesn't, you set the left bound to ~mid + 1~. After about ~10~ submissions, you will be able to guess n of ~1~ test.
Do note that it's manual binary search (you do it by hand), not regular binary search.
This also works with bigger input (~2+~ integers, a whole array, etc.). For instance, you are trying to guess tests of a problem in which input consists of an array. You guess ~n~ using the method above, and guess ~a_i~ for all ~1 \le i \le n~ using the same mentioned method. Though if the array is long (~10^6+~ elements), good luck with staying up all night to submit your code tens of millions of times.