Hi Codeforces. Today i saw GreenGrape solution of the problem D. Robot Vacuum Cleaner : 35053688. And i find there :
#define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
while (t--) {
clock_t z = clock();
solve();
debug("Total Time: %.3f\n", (double)(clock() - z) / CLOCKS_PER_SEC);
}
With this code he gets execution time of function solve()
. clock()
gives you current time. It is useful to avoid time limits. I have wrote helpful macro and decided to share with you :
#define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#define time__(d)for(long blockTime=NULL;(blockTime==NULL?(blockTime=clock())!=NULL:false); debug("%s:%.4fs",d,(double)(clock()-blockTime)/CLOCKS_PER_SEC))
with this u can get execution time of parts of your programm. Example:
int main () {
time__("dfs time"){
/* dfs code */
}
}
And programm will print something like dfs time : 0.265s
. You don't need to erase debugging part when you will submit it. Example submission: 35088800. Thank you for reading and I hope it will help you