Блог пользователя Bakry

Автор Bakry, история, 8 лет назад, По-английски

hello, there's something weird happened to me in szkopul website which caused TLE and after small changes to the code, it got AC..it happened to me in 2 problems.

1 — first problem : POI10-sums

I got 90 with this code and got TLE in test case 8 , but after that I got the full score using this code , the only difference between the two codes is that loop in dijkstra which in first code is :

for(int i = 0 ; i < n ; ++i)
{
    int now2 = now + arr[i] ;
    int cur2 = (cur + arr[i]) % arr[0] ;
    if(now2 > 1e9)
        continue ;
    if(now2 < vis[cur2] && now2 <= 1e9)
    {
        vis[cur2] = now2 ;
        q.push({now2 , cur2}) ;
    }
}

but in second code it's :

for(int i = 0 ; i < n ; ++i)
{
    int now2 = now + arr[i] ;
    int cur2 = (cur + arr[i]) % arr[0] ;
    //if(now2 > 1e9)
    //    continue ;
    if(now2 < vis[cur2] && now2 <= 1e9)
    {
        vis[cur2] = now2 ;
        q.push({now2 , cur2}) ;
    }
}

so the only difference is that I put this comment , there's no additional loop or nothing and the condition also was right.

2 — second problem : POI15-seals

I got 56 with this code and got TLE at test case 6, 7, 8, and 9, after that I made a small change and got 100 with this code, the only difference is that I made

char arr[n][m] , arr2[a][b] ;

in the first code , and replaced it with

vector<string>arr(n) ;
vector<string>arr2(a);

in the second code, and I don't think that makes that great difference because it's the same time in taking input.

so I would like to know what makes first codes in this two problems get TLE and after very small differences it got the full score even that these small differences don't affect the time of the codes.

hope the blog wasn't long and hope to know the reason of TLE.

Thanks.

  • Проголосовать: нравится
  • +12
  • Проголосовать: не нравится

»
8 лет назад, скрыть # |
← Rev. 5  
Проголосовать: нравится 0 Проголосовать: не нравится

Compiler optimization and/or different complexities of different standard library functions are often the main reasons for making tangible differences in the execution-time and memory requirements in response to small changes in the code. Note that the TLE verdict may not tell you the amount of time by which the first code exceeded the time-limit thershold. Only 1 msec above the time-limit is sufficient to produce the TLE verdict.

  • »
    »
    8 лет назад, скрыть # ^ |
     
    Проголосовать: нравится 0 Проголосовать: не нравится

    In the first problem: the difference between the AC code and the TLE code is more than 0.12 sec...and the difference between the two codes is the if condition, will just an if condition make that difference ?!

    • »
      »
      »
      8 лет назад, скрыть # ^ |
      ← Rev. 3  
      Проголосовать: нравится 0 Проголосовать: не нравится

      The very-small difference in the high-level C++ source codes does not necessarily imply that the difference between the execution times of the complied object codes should be very-small as well. For example, if you define one of the arguments of some user-defined function in C++ as an object without using the reference operator '&' before the object name, then the C++ complier implicitly generates object code to create a new copy of the passed object, leaving the object in the function call unchanged. This very small change, only the '&' operator, can easily generate a TLE verdict if the size of the copied object is large, and the function call is repeated a large number of times inside a loop.