結果

問題 No.458 異なる素数の和
ユーザー 👑 tatt61880tatt61880
提出日時 2021-04-10 19:12:58
言語 Kuin
(KuinC++ v.2021.9.17)
結果
AC  
実行時間 943 ms / 2,000 ms
コード長 749 bytes
コンパイル時間 2,316 ms
コンパイル使用メモリ 153,864 KB
実行使用メモリ 4,352 KB
最終ジャッジ日時 2023-10-14 18:24:57
合計ジャッジ時間 8,475 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
4,348 KB
testcase_01 AC 291 ms
4,348 KB
testcase_02 AC 347 ms
4,352 KB
testcase_03 AC 59 ms
4,352 KB
testcase_04 AC 78 ms
4,348 KB
testcase_05 AC 796 ms
4,348 KB
testcase_06 AC 328 ms
4,352 KB
testcase_07 AC 4 ms
4,352 KB
testcase_08 AC 786 ms
4,348 KB
testcase_09 AC 18 ms
4,352 KB
testcase_10 AC 2 ms
4,352 KB
testcase_11 AC 943 ms
4,348 KB
testcase_12 AC 2 ms
4,348 KB
testcase_13 AC 2 ms
4,352 KB
testcase_14 AC 2 ms
4,348 KB
testcase_15 AC 2 ms
4,352 KB
testcase_16 AC 34 ms
4,348 KB
testcase_17 AC 1 ms
4,348 KB
testcase_18 AC 2 ms
4,348 KB
testcase_19 AC 2 ms
4,352 KB
testcase_20 AC 2 ms
4,348 KB
testcase_21 AC 2 ms
4,348 KB
testcase_22 AC 2 ms
4,348 KB
testcase_23 AC 2 ms
4,348 KB
testcase_24 AC 1 ms
4,348 KB
testcase_25 AC 1 ms
4,352 KB
testcase_26 AC 2 ms
4,352 KB
testcase_27 AC 306 ms
4,348 KB
testcase_28 AC 913 ms
4,348 KB
testcase_29 AC 9 ms
4,348 KB
testcase_30 AC 198 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

func main()
	var n: int :: cui@inputInt()
	var isPrime: []bool :: sieve(n)
	var dp: []int :: #[n + 1]int
	for p(2, n)
		if(isPrime[p])
			for i(n, 2, -1)
				if(dp[i] <> 0)
					if(i + p <= n)
						do dp[i + p] :: [dp[i + p], dp[i] + 1].max()
					end if
				end if
			end for
			do dp[p] :: [dp[p], 1].max()
		end if
	end for
	var m: int :: dp[n] = 0 ?(-1, dp[n])
	do cui@print("\{m}\n")
	
	func sieve(n: int): []bool
		if(n < 2)
			ret[false].repeat(n + 1)
		end if
		var isPrime: []bool :: [true].repeat(n + 1)
		do isPrime[0] :: false
		do isPrime[1] :: false
		for i(2, n)
			if(isPrime[i])
				var j: int :: i * i
				while(j <= n)
					do isPrime[j] :: false
					do j :+ i
				end while
			end if
		end for
		ret isPrime
	end func
end func
0