結果

問題 No.458 異なる素数の和
ユーザー mol__mol__molmol__mol__mol
提出日時 2018-04-20 19:47:35
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 647 bytes
コンパイル時間 301 ms
コンパイル使用メモリ 87,108 KB
実行使用メモリ 432,984 KB
最終ジャッジ日時 2023-09-09 12:05:37
合計ジャッジ時間 15,664 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 87 ms
76,344 KB
testcase_01 AC 639 ms
171,960 KB
testcase_02 AC 818 ms
194,544 KB
testcase_03 AC 184 ms
85,416 KB
testcase_04 AC 230 ms
105,620 KB
testcase_05 AC 1,905 ms
373,156 KB
testcase_06 AC 791 ms
194,308 KB
testcase_07 AC 92 ms
76,364 KB
testcase_08 AC 1,899 ms
375,860 KB
testcase_09 AC 119 ms
83,808 KB
testcase_10 AC 70 ms
71,340 KB
testcase_11 TLE -
testcase_12 AC 75 ms
71,404 KB
testcase_13 AC 71 ms
71,000 KB
testcase_14 AC 71 ms
71,296 KB
testcase_15 AC 72 ms
71,376 KB
testcase_16 AC 146 ms
85,412 KB
testcase_17 AC 78 ms
76,020 KB
testcase_18 AC 80 ms
76,248 KB
testcase_19 AC 71 ms
71,444 KB
testcase_20 AC 82 ms
75,864 KB
testcase_21 AC 70 ms
71,296 KB
testcase_22 AC 71 ms
71,008 KB
testcase_23 AC 78 ms
75,912 KB
testcase_24 AC 84 ms
76,124 KB
testcase_25 AC 73 ms
71,004 KB
testcase_26 AC 77 ms
75,932 KB
testcase_27 AC 754 ms
194,148 KB
testcase_28 TLE -
testcase_29 AC 107 ms
76,580 KB
testcase_30 AC 470 ms
149,856 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

default = -100000
n = int(input())
primes = [100000]
lst = [0 if (i == 0 or i == 1) else 1 for i in range(n + 1)]
for i in range(n + 1):
  if lst[i]:
    primes.append(i)
    for j in range(i * 2,n + 1,i):
      lst[j] = 0
dp = [[1 if i == primes[j] else default for j in range(len(primes))] for i in range(n + 1)] 
for i in range(2,n + 1):
  for j in range(1,len(primes)):
    if i == 0 or i == 1 or j == 0:
      dp[i][j] = 0
    elif i >= primes[j]:
      dp[i][j] = max(dp[i][j],dp[i][j - 1], dp[i - primes[j]][j - 1] + 1)
    else:
      dp[i][j] = dp[i][j - 1]
if dp[n][len(primes) - 1] < 0:
  print(-1)
else:
  print(dp[n][len(primes) - 1])
0