結果

問題 No.458 異なる素数の和
ユーザー tentententen
提出日時 2023-01-06 12:32:37
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,945 bytes
コンパイル時間 2,795 ms
コンパイル使用メモリ 81,648 KB
実行使用メモリ 53,128 KB
最終ジャッジ日時 2023-08-20 06:49:35
合計ジャッジ時間 8,479 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 46 ms
49,276 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 50 ms
49,832 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 47 ms
49,456 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;
import java.util.stream.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        int n = sc.nextInt();
        boolean[] isNotPrime = new boolean[n + 1];
        int[] counts = new int[n + 1];
        Arrays.fill(counts, -1);
        counts[0] = 0;
        for (int i = 2; i <= n; i++) {
            if (!isNotPrime[i]) {
                for (int j = n - i; j >= 0; j--) {
                    if (counts[j] >= 0) {
                        counts[j + i] = Math.max(counts[j + i], counts[j] + 1);
                    }
                }
            }
        }
        System.out.println(counts[n]);
    }
    
}

class Utilities {
    static String arrayToLineString(Object[] arr) {
        return Arrays.stream(arr).map(x -> x.toString()).collect(Collectors.joining("\n"));
    }
    
    static String arrayToLineString(int[] arr) {
        return String.join("\n", Arrays.stream(arr).mapToObj(String::valueOf).toArray(String[]::new));
    }
}
class Scanner {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st = new StringTokenizer("");
    StringBuilder sb = new StringBuilder();
    
    public Scanner() throws Exception {
        
    }
    
    public int nextInt() throws Exception {
        return Integer.parseInt(next());
    }
    
    public long nextLong() throws Exception {
        return Long.parseLong(next());
    }
    
    public double nextDouble() throws Exception {
        return Double.parseDouble(next());
    }
    
    public int[] nextIntArray() throws Exception {
        return Stream.of(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray();
    }
    
    public String next() throws Exception {
        while (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
    
}
0