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

Автор CarViz, история, 13 часов назад, По-английски

hello all

will delete next period

can you guys figure out why im runtime erroring

391906583

thanks,

edit: i didnt generate enough primes whoops.

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

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

first time seeing normal blog by CarViz

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

    A normal blog by Carviz before GTA6?

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

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

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

I think the runtime error is most likely caused by this line:

while (i+1)*primel[lp]-1 < len(l):

You access primel[lp] before checking whether lp is still within the bounds of primel. If lp becomes equal to len(primel), this causes an IndexError: list index out of range.

Also, this line can cause an IndexError if any value in l is greater than len(l):

sum([dp[i-1] for i in l])

For example, if len(l) = 3 but l contains 100, then dp[99] is out of bounds.

You should check the constraints and make sure the prime list is large enough, and also verify that every value in l is a valid index for dp.

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

will delete next period

I guess he learned how to pocket solve

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

I didn't even notice that this was DP during the entire contest :(. I just assumed you can greedily take the lowest power like a noob. Wrong answered test 6.