結果

問題 No.458 異なる素数の和
ユーザー suppy193suppy193
提出日時 2017-02-01 11:59:54
言語 Ruby
(3.3.0)
結果
TLE  
実行時間 -
コード長 417 bytes
コンパイル時間 45 ms
コンパイル使用メモリ 11,344 KB
実行使用メモリ 88,152 KB
最終ジャッジ日時 2023-08-25 17:07:54
合計ジャッジ時間 10,566 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 91 ms
16,072 KB
testcase_01 TLE -
testcase_02 TLE -
testcase_03 AC 527 ms
87,188 KB
testcase_04 AC 648 ms
87,216 KB
testcase_05 TLE -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.rb:26: warning: ambiguous first argument; put parentheses or a space even after `-' operator
Syntax OK

ソースコード

diff #

require 'prime'

n = gets.strip.to_i

primes = []
primes << 2
i = 3
while i < n
	primes << i if i.prime?
	i += 2
end
# p primes
@memo = Hash.new(0)
primes.each do |prime|
	@memo_next = @memo.clone
	@memo.each do |k, v|
		next if k + prime > n
		@memo_next[k + prime] = [@memo[k + prime], v + 1].max
	end
	@memo_next[prime] = [1, @memo[prime]].max
	@memo = @memo_next
end
if @memo.key?(n)
	p @memo[n]
else
	puts -1
end
0