Codeforces celebrates 10 years! We are pleased to announce the crowdfunding-campaign. Congratulate us by the link https://codeforces.com/10years. ×

PracticeAccountICL's blog

By PracticeAccountICL, history, 4 weeks ago, In English,

I'm looking at 2 identical solutions to:(1280A) https://codeforces.com/contest/1280/problem/A, both written in python. However, one of them reaches time limit exceeded on test 6 whereas the other gets accepted. I don't understand why one solution takes longer than the other when they're both so similar, can someone help me?

Solution1[timed out at test6]: 69618709 https://codeforces.com/contest/1280/submission/69618709

Solution2[accepted]: 69621733 https://codeforces.com/contest/1280/submission/69621733

 
 
 
 
  • Vote: I like it
  • -3
  • Vote: I do not like it

»
4 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

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

»
4 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

Ok so i moved the modulo inside the for loop and now the first solution is faster but it still times out at test 18: https://codeforces.com/contest/1280/submission/69623457

»
4 weeks ago, # |
  Vote: I like it +6 Vote: I do not like it

nevermind, i figured it out. if you multiply the list, the time complexity is much greater. i used a for loop and appended the slices 1 by 1 and my solution is now accepted