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

Автор blackBird, 14 лет назад, По-английски

Hi, This concerns two solutions of the same problems (problem D round 136 div 2 Link: http://www.codeforces.com/problemset/problem/221/D ).

The player, zhaozhiyun, submitted a code VERY similar to mine. His got accepted while mine got TLE'd. Here are the links to the two solutions.

His, Link 1: (Accepted one) http://www.codeforces.com/contest/221/submission/2081857 Mine, Link 2: (TLE one) http://www.codeforces.com/contest/221/submission/2078483

Can anyone tell why mine got TLE'd while his accept even though we have almost the same codes ?

Is it because of different server load during system test, etc ?

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

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

If it happened to me as well an explanation please

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

I think contestant zhaozhiyun is just lucky. Because he got Accepted with time 3840ms of 4000 admissible.

»
14 лет назад, скрыть # |
 
Проголосовать: нравится +4 Проголосовать: не нравится

This is what I think:

In the final part of the solution, zhaozhiyun's code loads each v[a] into the CPU cache only once and then iterates over all l[i] and r[i]. Your code reloads all v[a] for each query and thrashes the CPU cache. The cost of having the arrays l and r is relatively low, as they are accessed linearly and the CPU can predict this.