結果

問題 No.458 異なる素数の和
ユーザー zimphazimpha
提出日時 2017-04-02 14:51:23
言語 Java21
(openjdk 21)
結果
AC  
実行時間 119 ms / 2,000 ms
コード長 2,229 bytes
コンパイル時間 1,946 ms
コンパイル使用メモリ 74,500 KB
実行使用メモリ 53,048 KB
最終ジャッジ日時 2023-09-22 07:36:51
合計ジャッジ時間 5,068 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
47,412 KB
testcase_01 AC 76 ms
50,976 KB
testcase_02 AC 78 ms
51,200 KB
testcase_03 AC 59 ms
50,788 KB
testcase_04 AC 64 ms
50,900 KB
testcase_05 AC 106 ms
51,040 KB
testcase_06 AC 82 ms
51,104 KB
testcase_07 AC 45 ms
49,468 KB
testcase_08 AC 107 ms
50,804 KB
testcase_09 AC 55 ms
51,196 KB
testcase_10 AC 41 ms
49,468 KB
testcase_11 AC 119 ms
53,048 KB
testcase_12 AC 43 ms
49,508 KB
testcase_13 AC 42 ms
49,444 KB
testcase_14 AC 42 ms
49,356 KB
testcase_15 AC 43 ms
49,556 KB
testcase_16 AC 58 ms
50,956 KB
testcase_17 AC 44 ms
49,600 KB
testcase_18 AC 44 ms
49,620 KB
testcase_19 AC 44 ms
49,344 KB
testcase_20 AC 44 ms
49,596 KB
testcase_21 AC 43 ms
49,772 KB
testcase_22 AC 43 ms
49,664 KB
testcase_23 AC 43 ms
49,672 KB
testcase_24 AC 43 ms
49,612 KB
testcase_25 AC 43 ms
49,556 KB
testcase_26 AC 43 ms
49,464 KB
testcase_27 AC 77 ms
51,052 KB
testcase_28 AC 115 ms
51,408 KB
testcase_29 AC 51 ms
49,428 KB
testcase_30 AC 70 ms
51,216 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Chiaki.Hoshinomori
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Task458 solver = new Task458();
        solver.solve(1, in, out);
        out.close();
    }

    static class Task458 {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int[] dp = new int[n + 1];
            Arrays.fill(dp, -1);
            boolean[] mark = new boolean[n + 1];
            dp[0] = 0;
            for (int i = 2; i <= n; i++) {
                if (mark[i]) continue;
                for (int j = n; j >= i; --j) {
                    if (dp[j - i] == -1) continue;
                    dp[j] = Math.max(dp[j], dp[j - i] + 1);
                }
                for (int j = i; j <= n; j += i) {
                    mark[j] = true;
                }
            }
            out.println(dp[n]);
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}

0