結果
問題 | No.458 異なる素数の和 |
ユーザー | 14番 |
提出日時 | 2017-02-12 06:55:26 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
AC
|
実行時間 | 1,046 ms / 2,000 ms |
コード長 | 2,618 bytes |
コンパイル時間 | 2,117 ms |
コンパイル使用メモリ | 106,540 KB |
実行使用メモリ | 217,028 KB |
最終ジャッジ日時 | 2023-09-18 15:20:53 |
合計ジャッジ時間 | 10,291 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge14 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 57 ms
20,652 KB |
testcase_01 | AC | 309 ms
80,812 KB |
testcase_02 | AC | 395 ms
95,848 KB |
testcase_03 | AC | 104 ms
34,124 KB |
testcase_04 | AC | 122 ms
38,028 KB |
testcase_05 | AC | 882 ms
184,680 KB |
testcase_06 | AC | 365 ms
91,700 KB |
testcase_07 | AC | 57 ms
20,744 KB |
testcase_08 | AC | 885 ms
185,908 KB |
testcase_09 | AC | 71 ms
24,992 KB |
testcase_10 | AC | 55 ms
20,712 KB |
testcase_11 | AC | 1,046 ms
217,028 KB |
testcase_12 | AC | 56 ms
22,692 KB |
testcase_13 | AC | 55 ms
20,660 KB |
testcase_14 | AC | 56 ms
20,768 KB |
testcase_15 | AC | 56 ms
20,656 KB |
testcase_16 | AC | 84 ms
28,480 KB |
testcase_17 | AC | 56 ms
20,656 KB |
testcase_18 | AC | 55 ms
20,600 KB |
testcase_19 | AC | 56 ms
20,704 KB |
testcase_20 | AC | 56 ms
22,712 KB |
testcase_21 | AC | 55 ms
20,768 KB |
testcase_22 | AC | 56 ms
20,716 KB |
testcase_23 | AC | 56 ms
22,780 KB |
testcase_24 | AC | 56 ms
20,772 KB |
testcase_25 | AC | 55 ms
20,772 KB |
testcase_26 | AC | 56 ms
22,716 KB |
testcase_27 | AC | 353 ms
88,296 KB |
testcase_28 | AC | 1,041 ms
212,948 KB |
testcase_29 | AC | 64 ms
24,628 KB |
testcase_30 | AC | 232 ms
62,916 KB |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
using System; using System.Linq; using System.Collections.Generic; using System.Text.RegularExpressions; using System.Text; public class Program { public void Proc() { Reader.IsDebug = false; this.Num = int.Parse(Reader.ReadLine()); this.InitPrimeList(this.Num); this.memo = new Nullable<int>[this.PrimeList.Length, this.Num+1]; int ans = this.GetAns(0, this.Num); Console.WriteLine(ans); } private Nullable<int>[,] memo; private int GetAns(int idx, int remain) { if(idx >= this.PrimeList.Length) { if(remain == 0) { return 0; } else { return -1; } } if(remain == 0) { return 0; } if(remain < 2) { return -1; } if(this.memo[idx, remain] != null) { return this.memo[idx, remain].Value; } int ans = -1; if(PrimeList[idx] <= remain) { int ret = this.GetAns(idx+1, remain-PrimeList[idx]); if(ret >= 0) { ret++; ans = Math.Max(ans, ret); } ret = this.GetAns(idx+1, remain); if(ret >= 0) { ans = Math.Max(ans, ret); } } else { int ret = this.GetAns(idx+1, remain); if(ret >= 0) { ans = Math.Max(ans, ret); } } this.memo[idx, remain] = ans; return ans; } private int[] PrimeList; private void InitPrimeList(int num) { bool[] flags = new bool[num+1]; List<int> list = new List<int>(); for(int i=2; i<=num; i++) { if(flags[i]) { continue; } list.Add(i); for(int j=1; j*i<=num; j++) { flags[i*j] = true; } } list.Reverse(); this.PrimeList = list.ToArray(); } private int Num; public class Reader { public static bool IsDebug = true; private static System.IO.StringReader SReader; private static string InitText = @" 20000 "; public static string ReadLine() { if(IsDebug) { if(SReader == null) { SReader = new System.IO.StringReader(InitText.Trim()); } return SReader.ReadLine(); } else { return Console.ReadLine(); } } } public static void Main(string[] args) { Program prg = new Program(); prg.Proc(); } }