結果
問題 | No.12 限定された素数 |
ユーザー | バカらっく |
提出日時 | 2017-06-28 02:51:16 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
AC
|
実行時間 | 410 ms / 5,000 ms |
コード長 | 2,741 bytes |
コンパイル時間 | 3,771 ms |
コンパイル使用メモリ | 107,104 KB |
実行使用メモリ | 37,376 KB |
最終ジャッジ日時 | 2023-08-16 00:42:42 |
合計ジャッジ時間 | 11,085 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge13 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 204 ms
33,280 KB |
testcase_01 | AC | 281 ms
35,172 KB |
testcase_02 | AC | 228 ms
37,376 KB |
testcase_03 | AC | 410 ms
35,220 KB |
testcase_04 | AC | 229 ms
35,232 KB |
testcase_05 | AC | 317 ms
35,140 KB |
testcase_06 | AC | 332 ms
37,260 KB |
testcase_07 | AC | 359 ms
37,168 KB |
testcase_08 | AC | 287 ms
35,168 KB |
testcase_09 | AC | 251 ms
33,768 KB |
testcase_10 | AC | 308 ms
35,068 KB |
testcase_11 | AC | 385 ms
35,216 KB |
testcase_12 | AC | 355 ms
35,884 KB |
testcase_13 | AC | 315 ms
33,040 KB |
testcase_14 | AC | 294 ms
37,180 KB |
testcase_15 | AC | 319 ms
35,196 KB |
testcase_16 | AC | 384 ms
35,248 KB |
testcase_17 | AC | 204 ms
35,124 KB |
testcase_18 | AC | 205 ms
37,176 KB |
testcase_19 | AC | 204 ms
37,204 KB |
testcase_20 | AC | 234 ms
37,236 KB |
testcase_21 | AC | 265 ms
37,184 KB |
testcase_22 | AC | 204 ms
37,188 KB |
testcase_23 | AC | 206 ms
37,220 KB |
testcase_24 | AC | 203 ms
35,780 KB |
testcase_25 | AC | 312 ms
35,364 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.IO; using System.Linq; using System.Collections.Generic; using System.Text; public class Program { public void Proc() { int itemCount = int.Parse(Reader.ReadLine()); char[] items = Reader.ReadLine().Split(' ').Select(a => a[0]).ToArray(); this.PrimeList = this.GetPrimeList(); int fromIdx = -1; int toIdx = -1; int ans = -1; Dictionary<char, bool> cnt = new Dictionary<char, bool>(); items.ToList().ForEach(a=>cnt.Add(a, false)); for (int i = 0; i < PrimeList.Length; i++) { string num = PrimeList[i].ToString(); if(num.All(a=>cnt.ContainsKey(a))) { if (fromIdx < 0) { fromIdx = i; } toIdx = i; num.ToList().ForEach(a => cnt[a] = true); } else { if (fromIdx >= 0 && cnt.All(a=>a.Value)) { int fromNum = 1; if (fromIdx > 0) { fromNum = PrimeList[fromIdx-1]+1; } int toNum = 5000000; if(toIdx < PrimeList.Length - 1) { toNum = PrimeList[toIdx + 1] - 1; } ans = Math.Max(ans, toNum - fromNum); } fromIdx = -1; toIdx = -1; cnt.Keys.ToList().ForEach(a => cnt[a] = false); } } if(toIdx >= 0) { int fromNum = 1; if (fromIdx>0) { fromNum = PrimeList[fromIdx - 1] + 1; } ans = Math.Max(ans, 5000000 - fromNum); } Console.WriteLine(ans); } private int[] GetPrimeList() { int num = 5000000; bool[] flags = new bool[num + 1]; List<int> ret = new List<int>(); for (int i = 2; i <= num; i++) { if (flags[i]) { continue; } ret.Add(i); int max = num / i; for (int j = 0; j <= max; j++) { flags[i*j] = true; } } return ret.ToArray(); } private int[] PrimeList; public class Reader { private static StringReader sr; public static bool IsDebug = false; public static string ReadLine() { if (IsDebug) { if (sr == null) { sr = new StringReader(InputText.Trim()); } return sr.ReadLine(); } else { return Console.ReadLine(); } } private static string InputText = @" 5 1 2 3 4 5 "; } public static void Main(string[] args) { #if DEBUG Reader.IsDebug = true; #endif Program prg = new Program(); prg.Proc(); } }