結果

問題 No.458 異なる素数の和
ユーザー 👑 tatt61880tatt61880
提出日時 2021-08-11 22:42:53
言語 Kuin
(KuinC++ v.2021.9.17)
結果
AC  
実行時間 70 ms / 2,000 ms
コード長 687 bytes
コンパイル時間 5,444 ms
コンパイル使用メモリ 147,268 KB
実行使用メモリ 4,372 KB
最終ジャッジ日時 2023-10-26 00:39:29
合計ジャッジ時間 6,898 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 21 ms
4,372 KB
testcase_02 AC 27 ms
4,372 KB
testcase_03 AC 6 ms
4,372 KB
testcase_04 AC 8 ms
4,372 KB
testcase_05 AC 58 ms
4,372 KB
testcase_06 AC 26 ms
4,372 KB
testcase_07 AC 2 ms
4,372 KB
testcase_08 AC 55 ms
4,372 KB
testcase_09 AC 3 ms
4,372 KB
testcase_10 AC 2 ms
4,372 KB
testcase_11 AC 70 ms
4,372 KB
testcase_12 AC 2 ms
4,372 KB
testcase_13 AC 2 ms
4,372 KB
testcase_14 AC 1 ms
4,372 KB
testcase_15 AC 1 ms
4,372 KB
testcase_16 AC 4 ms
4,372 KB
testcase_17 AC 1 ms
4,372 KB
testcase_18 AC 2 ms
4,372 KB
testcase_19 AC 2 ms
4,372 KB
testcase_20 AC 2 ms
4,372 KB
testcase_21 AC 1 ms
4,372 KB
testcase_22 AC 2 ms
4,372 KB
testcase_23 AC 2 ms
4,372 KB
testcase_24 AC 2 ms
4,372 KB
testcase_25 AC 2 ms
4,372 KB
testcase_26 AC 2 ms
4,372 KB
testcase_27 AC 24 ms
4,372 KB
testcase_28 AC 68 ms
4,372 KB
testcase_29 AC 2 ms
4,372 KB
testcase_30 AC 16 ms
4,372 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] :: lib@max(dp[i + p], dp[i] + 1)
					end if
				end if
			end for
			do dp[p] :: lib@max(dp[p], 1)
		end if
	end for
	var m: int :: dp[n] = 0 ?(-1, dp[n])
	do cui@print("\{m}\n")
end func

func sieve(n: int): []bool
	if(n < 2)
		ret [false].repeat(n + 1)
	end if
	var res: []bool :: [false, false] ~ [true].repeat(n - 1)
	for i(2, n)
		if(res[i])
			var j: int :: i * i
			while(j <= n)
				do res[j] :: false
				do j :+ i
			end while
		end if
	end for
	ret res
end func
0