結果

問題 No.458 異なる素数の和
ユーザー ああいいああいい
提出日時 2022-01-28 13:43:05
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,664 ms / 2,000 ms
コード長 667 bytes
コンパイル時間 305 ms
コンパイル使用メモリ 87,160 KB
実行使用メモリ 430,884 KB
最終ジャッジ日時 2023-08-28 10:37:58
合計ジャッジ時間 13,431 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 84 ms
76,128 KB
testcase_01 AC 570 ms
177,952 KB
testcase_02 AC 690 ms
202,824 KB
testcase_03 AC 189 ms
89,064 KB
testcase_04 AC 230 ms
105,740 KB
testcase_05 AC 1,420 ms
371,828 KB
testcase_06 AC 656 ms
201,564 KB
testcase_07 AC 90 ms
76,312 KB
testcase_08 AC 1,402 ms
374,128 KB
testcase_09 AC 125 ms
83,760 KB
testcase_10 AC 73 ms
71,156 KB
testcase_11 AC 1,664 ms
430,884 KB
testcase_12 AC 76 ms
71,368 KB
testcase_13 AC 71 ms
71,120 KB
testcase_14 AC 71 ms
71,560 KB
testcase_15 AC 73 ms
71,356 KB
testcase_16 AC 152 ms
89,588 KB
testcase_17 AC 77 ms
76,000 KB
testcase_18 AC 81 ms
75,904 KB
testcase_19 AC 72 ms
71,120 KB
testcase_20 AC 79 ms
75,968 KB
testcase_21 AC 74 ms
71,320 KB
testcase_22 AC 73 ms
71,060 KB
testcase_23 AC 82 ms
76,008 KB
testcase_24 AC 80 ms
76,084 KB
testcase_25 AC 74 ms
71,280 KB
testcase_26 AC 77 ms
76,032 KB
testcase_27 AC 627 ms
195,344 KB
testcase_28 AC 1,600 ms
423,416 KB
testcase_29 AC 103 ms
76,200 KB
testcase_30 AC 423 ms
149,752 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N = int(input())
dat = [0] * (N + 1)
p = []
for i in range(2,N+1):
    if dat[i] == 0:
        for j in range(i * 2,N+1,i):
            dat[j] = 1
        p.append(i)
import sys
if N == 1:
    print(-1)
    exit()
if N == 2 or N == 3:
    print(1)
    exit()
if N == 4:
    print(-1)
    exit()

n = len(p)
dp = [[-1] * (N+1) for _ in range(n)]
dp[0][p[0]] = 1
for i in range(n-1):
    for j in range(N+1):
        if dp[i][j] > 0:
            dp[i+1][j] = dp[i][j]
    for j in range(N+1):
        if dp[i][j] > 0 and j + p[i+1] <= N:
            dp[i+1][j+p[i+1]] = max(dp[i+1][j+p[i+1]],dp[i][j] + 1)
    dp[i+1][p[i+1]] = max(dp[i+1][p[i+1]],1)
print(dp[-1][-1])
0