結果
問題 | No.7 プライムナンバーゲーム |
ユーザー | AreTrash |
提出日時 | 2016-04-14 06:37:10 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
AC
|
実行時間 | 49 ms / 5,000 ms |
コード長 | 1,473 bytes |
コンパイル時間 | 2,461 ms |
コンパイル使用メモリ | 113,912 KB |
実行使用メモリ | 27,064 KB |
最終ジャッジ日時 | 2024-04-09 03:57:46 |
合計ジャッジ時間 | 2,429 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 28 ms
26,724 KB |
testcase_01 | AC | 28 ms
24,816 KB |
testcase_02 | AC | 49 ms
24,940 KB |
testcase_03 | AC | 30 ms
24,980 KB |
testcase_04 | AC | 28 ms
25,100 KB |
testcase_05 | AC | 29 ms
25,224 KB |
testcase_06 | AC | 35 ms
26,784 KB |
testcase_07 | AC | 32 ms
26,856 KB |
testcase_08 | AC | 29 ms
24,812 KB |
testcase_09 | AC | 38 ms
25,068 KB |
testcase_10 | AC | 28 ms
26,980 KB |
testcase_11 | AC | 33 ms
22,712 KB |
testcase_12 | AC | 44 ms
27,064 KB |
testcase_13 | AC | 44 ms
22,576 KB |
testcase_14 | AC | 49 ms
24,816 KB |
testcase_15 | AC | 48 ms
24,944 KB |
testcase_16 | AC | 47 ms
26,804 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.Collections.Generic; using System.Linq; namespace No7_1 { public class Program { public static void Main(string[] args) { var n = Read(Convert.ToInt32); var dp = new bool[n + 1]; var primeList = new List<int>(); var p = n; if(p > 1) { var numList = Enumerable.Range(2, p - 1).ToList(); var sqrt = (int)Math.Sqrt(p); while(numList[0] <= sqrt) { var prime = numList[0]; primeList.Add(prime); numList.RemoveAll(value => value % prime == 0); } primeList.AddRange(numList); } for(var i = 4; i <= n; i++){ foreach(var prime in primeList){ if(prime <= i - 2){ if(!dp[i - prime]){ dp[i] = true; break; } } } } Console.WriteLine(dp[n] ? "Win" : "Lose"); } public static TOutput Read<TOutput>(Converter<string, TOutput> converter) { return converter(Console.ReadLine()); } public static List<TOutput> ReadList<TOutput>(Converter<string, TOutput> converter, char c = ' ') { return Console.ReadLine()?.Split(c).ToList().ConvertAll(converter); } } }