'Getting runtime error on submission for Kattis "Perket" problem. I am getting the right output locally, what is wrong with my code?
I have struggled with the problem "Perket" from Kattis: https://open.kattis.com/problems/perket
I succeed locally when i manually write the samples, getting the correct output. I get "runtime error" when i try to submit to Kattis though. Does any of you see the mistake? Is my program too slow for the requirements? Thank you very much and have a nice day.
import math
n = int(input())
ingredients = []
for i in range(n):
new = [int(k) for k in input().split()]
ingredients.append(new)
bitter = [val[0] for val in ingredients]
sour = [val[1] for val in ingredients]
diffs = []
for i in range(len(bitter)):
for j in range(len(sour)):
diff = abs(math.prod(bitter[i:j+1]) - sum(sour[i:j+1]))
diffs.append(diff)
print(min(diffs))
Solution 1:[1]
I went ahead, and did a lot of black-box bisecting to debug the issue.
It turns out the validation breaks (with a Run Time Error) on math.prod.
math.prod was introduced in Python 3.8, so the website is likely using an older version of Python 3. You should try and create your own version of math.prod (or find another way to solve the problem).
Found the Python version, from https://open.kattis.com/help/python3 :
For Python 3, we use PyPy version Python 3.6.9 (7.3.1+dfsg-4, Apr 22 2020, 05:15:29) with the following flags: {files}.
For the record, CPython 3.6 has recently reached end of life (in December 2021). I'm not sure about the PyPy's version, but version 3.6 can't be downloaded from PyPy's website; only later versions.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
