結果

問題 No.458 異なる素数の和
ユーザー chika0707chika0707
提出日時 2019-09-11 18:59:47
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 157 ms / 2,000 ms
コード長 2,107 bytes
コンパイル時間 6,182 ms
コンパイル使用メモリ 106,284 KB
実行使用メモリ 23,792 KB
最終ジャッジ日時 2023-09-15 13:53:03
合計ジャッジ時間 6,078 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 62 ms
19,584 KB
testcase_01 AC 89 ms
21,800 KB
testcase_02 AC 97 ms
21,720 KB
testcase_03 AC 69 ms
23,684 KB
testcase_04 AC 70 ms
21,632 KB
testcase_05 AC 138 ms
21,720 KB
testcase_06 AC 95 ms
21,696 KB
testcase_07 AC 63 ms
21,632 KB
testcase_08 AC 139 ms
21,748 KB
testcase_09 AC 64 ms
21,792 KB
testcase_10 AC 62 ms
19,776 KB
testcase_11 AC 157 ms
23,736 KB
testcase_12 AC 62 ms
21,784 KB
testcase_13 AC 61 ms
21,740 KB
testcase_14 AC 62 ms
21,676 KB
testcase_15 AC 63 ms
23,636 KB
testcase_16 AC 65 ms
19,712 KB
testcase_17 AC 63 ms
23,644 KB
testcase_18 AC 67 ms
23,724 KB
testcase_19 AC 63 ms
21,744 KB
testcase_20 AC 62 ms
21,848 KB
testcase_21 AC 63 ms
21,756 KB
testcase_22 AC 65 ms
21,740 KB
testcase_23 AC 62 ms
23,768 KB
testcase_24 AC 64 ms
21,760 KB
testcase_25 AC 63 ms
21,748 KB
testcase_26 AC 63 ms
23,792 KB
testcase_27 AC 92 ms
19,580 KB
testcase_28 AC 153 ms
21,684 KB
testcase_29 AC 64 ms
19,704 KB
testcase_30 AC 81 ms
19,628 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

using System;
using System.Collections.Generic;
using System.Linq;
using static Input;

public class Prog
{
    public struct Pair { public int x, y; public Pair(int x, int y) { this.x = x; this.y = y; } }
    public static void Solve()
    {
        int N = NextInt();
        bool[] memo = Enumerable.Repeat(true, N + 1).ToArray();
        List<int> fact = new List<int>();
        for (int x = 2; x <= N; x++)
        {
            if (memo[x]) fact.Add(x);
            else continue;
            for (int t = 2; t * x <= N; t++) memo[t * x] = false;
        }
        int[] dp = Enumerable.Repeat(-INF, N + 1).ToArray();
        dp[0] = 0;
        foreach (var e in fact)
            for (int x = N - e; x >= 0; x--) dp[x + e] = Math.Max(dp[x + e], dp[x] + 1);
        Console.WriteLine(dp[N] > 0 ? dp[N] : -1);
    }
    public static void Main()
    {
        var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
        Console.SetOut(sw);
        Solve();
        Console.Out.Flush();
    }
}
public class Input
{
    public const long MOD = 1000000007;
    public const int INF = 1000000007;
    private static Queue<string> q = new Queue<string>();
    private static void Confirm() { if (q.Count == 0) foreach (var s in Console.ReadLine().Split(' ')) q.Enqueue(s); }
    public static int NextInt() { Confirm(); return int.Parse(q.Dequeue()); }
    public static long NextLong() { Confirm(); return long.Parse(q.Dequeue()); }
    public static string NextString() { Confirm(); return q.Dequeue(); }
    public static double NextDouble() { Confirm(); return double.Parse(q.Dequeue()); }
    public static int[] LineInt() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); }
    public static long[] LineLong() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); }
    public static string[] LineString() { return Console.ReadLine().Split(' ').ToArray(); }
    public static double[] LineDouble() { return Console.ReadLine().Split(' ').Select(double.Parse).ToArray(); }
    public long Abs(long a, long b) => Math.Abs(a - b);
}
0