結果

問題 No.458 異なる素数の和
ユーザー mbanmban
提出日時 2016-12-22 14:23:08
言語 C#(csc)
(csc 3.9.0)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 2,109 bytes
コンパイル時間 2,419 ms
コンパイル使用メモリ 105,764 KB
実行使用メモリ 196,976 KB
最終ジャッジ日時 2023-08-22 10:12:24
合計ジャッジ時間 17,114 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 56 ms
22,828 KB
testcase_01 AC 522 ms
73,152 KB
testcase_02 AC 699 ms
88,300 KB
testcase_03 AC 132 ms
33,424 KB
testcase_04 AC 160 ms
37,964 KB
testcase_05 AC 1,766 ms
170,204 KB
testcase_06 AC 661 ms
85,220 KB
testcase_07 AC 56 ms
20,676 KB
testcase_08 AC 1,820 ms
172,892 KB
testcase_09 AC 74 ms
29,184 KB
testcase_10 AC 55 ms
20,788 KB
testcase_11 TLE -
testcase_12 AC 57 ms
20,752 KB
testcase_13 AC 56 ms
20,796 KB
testcase_14 AC 55 ms
18,740 KB
testcase_15 AC 56 ms
20,804 KB
testcase_16 AC 89 ms
30,444 KB
testcase_17 AC 55 ms
20,684 KB
testcase_18 AC 54 ms
20,792 KB
testcase_19 AC 55 ms
20,852 KB
testcase_20 AC 55 ms
20,672 KB
testcase_21 AC 56 ms
22,936 KB
testcase_22 AC 55 ms
20,860 KB
testcase_23 AC 54 ms
20,784 KB
testcase_24 AC 55 ms
22,656 KB
testcase_25 AC 55 ms
20,676 KB
testcase_26 AC 55 ms
22,716 KB
testcase_27 AC 616 ms
82,708 KB
testcase_28 TLE -
testcase_29 AC 64 ms
24,572 KB
testcase_30 AC 379 ms
58,904 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;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Text;
using System.Text.RegularExpressions;
using System.Linq;

class Magatro
{
    static int[] Primes;
    static int N = int.Parse(Console.ReadLine());
    static void Main()
    {
        PrimeCalc();
        int[,] B = new int[20001, Primes.Length + 1];
        for(int i = 0; i <= N; i++)
        {
            for(int j = 0; j <= Primes.Length;j++)
            {
                B[i, j] = -1;
            }
        }
        B[0, 0] = 0;
        for(int i = 0; i < Primes.Length; i++)
        {
            for(int j = 0; j <= N; j++)
            {
                if (B[j, i] == -1)
                {
                    continue;
                }
                
                B[j, i + 1] =Math.Max(B[j, i], B[j, i + 1]);
                if (j + Primes[i] > N)
                {
                    continue;
                }
                if(B[j + Primes[i], i + 1]==-1)
                    B[j + Primes[i], i + 1] = B[j, i] + 1;
                else
                {
                    B[j + Primes[i], i + 1] = Math.Max(B[j, i] + 1, B[j + Primes[i], i + 1]);
                }
            }
        }
       int max = -1;
        for(int i = 1; i <= Primes.Length; i++)
        {
            max = Math.Max(max, B[N,i]);
        }
        Console.WriteLine(max);


    }
    static void PrimeCalc()
    {
        bool[] a = new bool[N + 1];
        a[0] = true;
        a[1] = true;
        for(int i = 2; i <= Math.Sqrt(N); i++)
        {
            if (!a[i])
            {
                for(int j = i * 2; j <= N; j += i)
                {
                    a[j] = true;
                }
            }
        }
        List<int> L = new List<int>();
        for(int i = 0; i <= N; i++)
        {
            if (!a[i])
            {
                L.Add(i);
            }
        }
        Primes = L.ToArray();
    }
}
struct A
{
    public A(int num,int cnt)
    {
        Num = num;
        Cnt = cnt;
    }
    public int Num;
    public int Cnt;
}
0