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

CarViz's blog

By CarViz, history, 6 weeks ago, In English

hello all

will delete next period

can you guys figure out why im runtime erroring

391906583

thanks,

edit: i didnt generate enough primes whoops.

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

»
6 weeks ago, hide # |
← Rev. 2  
Vote: I like it +8 Vote: I do not like it

first time seeing normal blog by CarViz

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

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

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

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.

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

will delete next period

I guess he learned how to pocket solve

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

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.