Codeforces Round 1133 (Div. 1, Div. 2) is coming soon! Register here. ×

lupengheyyds's blog

By lupengheyyds, history, 17 months ago, In English

In problem CF1416F Showing Off, I had a solution that would originally cause TLE. I passed the problem by implementing a time-out-hack.(a trick to avoid TLE ) However, even when I set the threshold to 6.1 seconds (problem time limit: 6 seconds), the solution still passed. How did it happen? The partial code:

while(dep[s]<=t){
    if((clock()-timecode)>6.1*CLOCKS_PER_SEC){//Time-out Hack
        cout<<"NO\n";
        return ;
    }
    setval(now,0);
    maxflow+=Dinic(s,INF);
}
signed main(){
    int timecode=clock();
    int T;cin>>T;
    while(T--)Work();
    return 0;
}

The complete code: https://www.luogu.me/paste/22udkyoi#

  • Vote: I like it
  • +8
  • Vote: I do not like it

»
17 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Auto comment: topic has been updated by lupengheyyds (previous revision, new revision, compare).

»
17 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

According to an experiment, (clock() - timecode) > x * CLOCKS_PER_SEC would regard 1 real second as around 1.05 ~ 1.1 seconds (whose accurate value is $$$\dfrac{2^{20}}{10^6}$$$ or $$$\dfrac{2^{30}}{10^9}$$$, I guess), so you might pass even if you set it to around 6.3 ~ 6.6 seconds.

This feature is really common among different judgers.

  • »
    »
    17 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    ...but it should be pointed out that such behavior is slightly dishonorable (except in AHCs).