結果

問題 No.458 異なる素数の和
ユーザー 抹茶アイス抹茶アイス
提出日時 2023-08-09 13:55:02
言語 C#
(.NET 8.0.203)
結果
AC  
実行時間 1,193 ms / 2,000 ms
コード長 1,608 bytes
コンパイル時間 11,984 ms
コンパイル使用メモリ 169,656 KB
実行使用メモリ 221,596 KB
最終ジャッジ日時 2024-04-27 08:52:04
合計ジャッジ時間 18,067 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 54 ms
30,848 KB
testcase_01 AC 358 ms
80,812 KB
testcase_02 AC 469 ms
96,540 KB
testcase_03 AC 93 ms
41,460 KB
testcase_04 AC 105 ms
44,912 KB
testcase_05 AC 989 ms
177,740 KB
testcase_06 AC 438 ms
92,588 KB
testcase_07 AC 55 ms
31,096 KB
testcase_08 AC 989 ms
179,016 KB
testcase_09 AC 62 ms
34,028 KB
testcase_10 AC 44 ms
29,548 KB
testcase_11 AC 1,193 ms
207,428 KB
testcase_12 AC 43 ms
29,552 KB
testcase_13 AC 41 ms
29,552 KB
testcase_14 AC 41 ms
29,552 KB
testcase_15 AC 42 ms
29,440 KB
testcase_16 AC 67 ms
36,592 KB
testcase_17 AC 43 ms
29,696 KB
testcase_18 AC 42 ms
29,568 KB
testcase_19 AC 42 ms
29,440 KB
testcase_20 AC 42 ms
29,544 KB
testcase_21 AC 43 ms
29,428 KB
testcase_22 AC 44 ms
29,312 KB
testcase_23 AC 43 ms
29,552 KB
testcase_24 AC 42 ms
29,184 KB
testcase_25 AC 41 ms
29,560 KB
testcase_26 AC 42 ms
29,460 KB
testcase_27 AC 409 ms
89,644 KB
testcase_28 AC 1,167 ms
203,592 KB
testcase_29 AC 58 ms
32,256 KB
testcase_30 AC 253 ms
221,596 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
  復元対象のプロジェクトを決定しています...
  /home/judge/data/code/main.csproj を復元しました (97 ms)。
MSBuild のバージョン 17.9.6+a4ecab324 (.NET)
  main -> /home/judge/data/code/bin/Release/net8.0/main.dll
  main -> /home/judge/data/code/bin/Release/net8.0/publish/

ソースコード

diff #

using System;
using System.Collections.Generic;
using System.Linq;

namespace yukicoder
{
    public class Program
    {
        public static void Main()
        {
            var n = int.Parse(Console.ReadLine());
            var k = Prime(n);
            var m = k.Count;
            var c = new int[n + 1, m + 1];
            c[0, 0] = 1;
            for(var i = 0; i < m; i++)
            {
                for(var j = 0; j <= n; j++)
                {
                    if(c[j, i] > 0)
                    {
                        c[j, i + 1] = Math.Max(c[j, i], c[j, i + 1]);
                        if (j + k[i] <= n)
                        {
                            c[j + k[i], i + 1] = Math.Max(c[j, i] + 1, c[j + k[i], i + 1]);
                        }
                    }
                }
            }
            Console.WriteLine(c[n, m] - 1);
        }
        static List<int> Prime(int n)
        {
            var isPrime = new bool[n + 1];
            var k = new List<int>();
            for (int i = 2; i <= n; i++)
            {
                isPrime[i] = true;
            }

            for (int i = 2; i * i <= n; i++)
            {
                if (isPrime[i])
                {
                    for (int j = i * i; j <= n; j += i)
                    {
                        isPrime[j] = false;
                    }
                }
            }

            for (int i = 2; i <= n; i++)
            {
                if (isPrime[i])
                {
                    k.Add(i);
                }
            }

            return k;
        }
    }
}
0