結果

問題 No.458 異なる素数の和
ユーザー 👑 horiesinitihoriesiniti
提出日時 2018-04-03 03:56:04
言語 Ruby
(3.3.0)
結果
RE  
実行時間 -
コード長 383 bytes
コンパイル時間 142 ms
コンパイル使用メモリ 11,296 KB
実行使用メモリ 15,720 KB
最終ジャッジ日時 2023-09-08 13:56:39
合計ジャッジ時間 16,617 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 91 ms
15,144 KB
testcase_01 AC 715 ms
15,300 KB
testcase_02 AC 909 ms
15,464 KB
testcase_03 AC 223 ms
15,432 KB
testcase_04 AC 263 ms
15,320 KB
testcase_05 AC 1,943 ms
15,520 KB
testcase_06 AC 859 ms
15,544 KB
testcase_07 AC 94 ms
15,340 KB
testcase_08 AC 1,960 ms
15,576 KB
testcase_09 AC 131 ms
15,196 KB
testcase_10 RE -
testcase_11 TLE -
testcase_12 AC 90 ms
15,080 KB
testcase_13 WA -
testcase_14 AC 89 ms
15,160 KB
testcase_15 AC 89 ms
15,116 KB
testcase_16 AC 165 ms
15,444 KB
testcase_17 AC 93 ms
15,296 KB
testcase_18 AC 89 ms
15,116 KB
testcase_19 AC 89 ms
15,240 KB
testcase_20 AC 90 ms
15,104 KB
testcase_21 AC 90 ms
15,368 KB
testcase_22 AC 89 ms
15,216 KB
testcase_23 AC 90 ms
15,260 KB
testcase_24 AC 90 ms
15,372 KB
testcase_25 AC 89 ms
15,188 KB
testcase_26 AC 90 ms
15,304 KB
testcase_27 AC 825 ms
15,452 KB
testcase_28 TLE -
testcase_29 AC 107 ms
15,204 KB
testcase_30 AC 541 ms
15,348 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.rb:28: warning: ambiguous first argument; put parentheses or a space even after `-' operator
Main.rb:5: warning: assigned but unused variable - t
Syntax OK

ソースコード

diff #

require 'prime'
n=gets.to_i
dp=[0]*(n+2)
x=Prime.each(n).to_a
t=n/2+2
sum=0
while x[0]*2<=n
	e=x.shift
	sum+=e
	sum=[n,sum].min
	(sum-e+1).times{|i|
		p2=(sum-e+1)-i
		p3=e+p2
		next if p3>n
		if dp[p2]>0 && dp[p3]<dp[p2]+1
			dp[p3]=dp[p2]+1
		end
	}
	dp[e]=[dp[e],1].max
end
ans=dp[n]
x.each{|e|
	p1=n-e
	break if p1<0
	ans=[ans,dp[p1]+1].max
}
if ans<2
	puts -1
else
	puts ans
end
0