結果

問題 No.458 異なる素数の和
ユーザー yakeshibayakeshiba
提出日時 2021-03-11 03:41:39
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 778 bytes
コンパイル時間 224 ms
コンパイル使用メモリ 82,176 KB
実行使用メモリ 423,168 KB
最終ジャッジ日時 2024-04-20 20:29:04
合計ジャッジ時間 9,588 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 1,040 ms
362,880 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 1,045 ms
365,568 KB
testcase_09 AC 82 ms
72,448 KB
testcase_10 AC 42 ms
52,404 KB
testcase_11 WA -
testcase_12 AC 43 ms
52,572 KB
testcase_13 AC 43 ms
52,480 KB
testcase_14 AC 44 ms
52,480 KB
testcase_15 AC 43 ms
52,096 KB
testcase_16 AC 116 ms
88,704 KB
testcase_17 WA -
testcase_18 AC 45 ms
58,624 KB
testcase_19 WA -
testcase_20 AC 49 ms
58,624 KB
testcase_21 WA -
testcase_22 AC 43 ms
52,480 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

def create_prime_list(limit):
    x = limit**0.5
    primes = []
    #print('x={0}'.format(x))
    nums = [x for x in range(2, limit+1)]
    while nums[0]<=x:
        primes.append(nums[0])
        current_prime = nums[0]
        nums = [x for x in nums if x%current_prime != 0]
    primes.extend(nums)
    return primes

n = int(input())

if n == 1:
    print(-1)
    exit()

plist = create_prime_list(n)

dp = [[-1]*(n+1) for _ in range(len(plist))]

for i,p in enumerate(plist):
    dp[i][p] = 1

for i in range(len(plist)):
    for S in range(1,n+1):
        if dp[i-1][S] >= 1:
            dp[i][S] = max(dp[i-1][S], dp[i][S])
        elif S-plist[i] >= 0 and dp[i-1][S-plist[i]] >= 1:
            dp[i][S] = max(dp[i-1][S-plist[i]]+1, dp[i][S])

print(dp[len(plist)-1][n])
0