/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1152ms 41.426 MiB
#2 Accepted 1171ms 41.41 MiB
#3 Accepted 1148ms 41.406 MiB
#4 Accepted 1419ms 41.828 MiB
#5 Accepted 1397ms 41.871 MiB

Code



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

    for i in range(1, M):
        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
    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:25:48
Judged At
2024-11-11 02:36:06
Judged By
Score
100
Total Time
1419ms
Peak Memory
41.871 MiB