/ SeriousOJ /

Record Detail

Runtime Error


  
# Status Time Cost Memory Cost
#1 Runtime Error Traceback (most recent call last): File "foo.py", line 35, in <module> File "foo.py", line 28, in main File "foo.py", line 7, in precalculate TypeError: 'float' object cannot be interpreted as an integer 64ms 20.879 MiB
#2 Runtime Error Traceback (most recent call last): File "foo.py", line 35, in <module> File "foo.py", line 28, in main File "foo.py", line 7, in precalculate TypeError: 'float' object cannot be interpreted as an integer 65ms 20.973 MiB

Code

def precalculate():
    M = 200001
    MOD = 1000000007
    dp = [MOD] * M
    dp[0] = 1  # Base case

    for i in range(1, int(200)**0.5 + 1):
        l = i * i
        if l >= M:
            break

        temp = [MOD] * M
        for j in range(l, M):
            if dp[j - l] != MOD and dp[j - l] > 0:
                temp[j] = min(temp[j], dp[j - l] + 1)
            temp[j] = min(dp[j], temp[j])

        for j in range(l, M):
            dp[j] = min(dp[j], temp[j])

    for i in range(1, M):
        if dp[i] == MOD:
            dp[i] = 0  # Mark as unreachable

    return dp

def main():
    dp = precalculate()  # Precalculate dp values
    t = int(input())
    for _ in range(t):
        x = int(input())
        print(dp[x] - 1)  # Output the result

if __name__ == "__main__":
    main()

Information

Submit By
Type
Submission
Problem
P1051 Square Sum
Language
PyPy 3 (Python 3.9.18 PyPy 7.3.15)
Submit At
2024-10-21 20:21:31
Judged At
2024-11-11 02:36:06
Judged By
Score
0
Total Time
65ms
Peak Memory
20.973 MiB