結果

問題 No.458 異なる素数の和
ユーザー terrafarmterrafarm
提出日時 2020-12-14 06:08:38
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,146 bytes
コンパイル時間 973 ms
コンパイル使用メモリ 81,804 KB
実行使用メモリ 81,816 KB
最終ジャッジ日時 2023-10-20 04:42:07
合計ジャッジ時間 7,655 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 102 ms
80,196 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 AC 140 ms
80,696 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 97 ms
79,844 KB
testcase_11 AC 459 ms
81,816 KB
testcase_12 AC 97 ms
79,856 KB
testcase_13 AC 97 ms
79,852 KB
testcase_14 AC 97 ms
79,840 KB
testcase_15 AC 96 ms
79,844 KB
testcase_16 AC 126 ms
80,692 KB
testcase_17 AC 97 ms
79,840 KB
testcase_18 AC 97 ms
79,848 KB
testcase_19 AC 96 ms
79,832 KB
testcase_20 WA -
testcase_21 AC 96 ms
79,840 KB
testcase_22 AC 95 ms
79,848 KB
testcase_23 WA -
testcase_24 AC 98 ms
80,180 KB
testcase_25 AC 97 ms
79,840 KB
testcase_26 AC 95 ms
79,852 KB
testcase_27 AC 229 ms
80,700 KB
testcase_28 AC 449 ms
81,808 KB
testcase_29 WA -
testcase_30 AC 183 ms
80,696 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import logging
import sys
from inspect import currentframe

sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline

logging.basicConfig(level=logging.DEBUG)


def sieve_eratosthenes(n):
    is_prime = [True] * (n + 1)
    is_prime[0] = is_prime[1] = False
    for i in range(2, n + 1):
        for j in range(2 * i, n + 1, i):
            is_prime[j] = False
    return is_prime


def dbg(*args):
    id2names = {id(v): k for k, v in currentframe().f_back.f_locals.items()}
    logging.debug(
        ", ".join(id2names.get(id(arg), "???") + " = " + repr(arg) for arg in args)
    )


def main():

    # 素数iを足す遷移を後ろからiより大きい数字に対して行う
    n = int(input())
    table = sieve_eratosthenes(n)
    dp = [-1] * (n + 1)
    for i, fl in enumerate(table):
        if fl:
            dp[i] = 1
    for i, fl in enumerate(table):
        if fl:
            for j in range(n, i, -1):
                if dp[j] >= 1 and j + i <= n:
                    dp[i + j] = max(dp[i + j], dp[j] + 1)
    # ans = max(dp)
    dbg(table)
    dbg(dp)
    ans = dp[n]
    print(ans)


if __name__ == "__main__":
    main()
0