結果
問題 | No.6 使いものにならないハッシュ |
ユーザー | バカらっく |
提出日時 | 2017-06-25 16:47:31 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
AC
|
実行時間 | 95 ms / 5,000 ms |
コード長 | 2,720 bytes |
コンパイル時間 | 2,782 ms |
コンパイル使用メモリ | 111,508 KB |
実行使用メモリ | 29,960 KB |
最終ジャッジ日時 | 2023-10-14 23:06:05 |
合計ジャッジ時間 | 6,480 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge15 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 62 ms
23,772 KB |
testcase_01 | AC | 61 ms
21,852 KB |
testcase_02 | AC | 95 ms
27,908 KB |
testcase_03 | AC | 66 ms
23,652 KB |
testcase_04 | AC | 68 ms
21,756 KB |
testcase_05 | AC | 71 ms
23,808 KB |
testcase_06 | AC | 79 ms
27,924 KB |
testcase_07 | AC | 71 ms
23,712 KB |
testcase_08 | AC | 73 ms
23,752 KB |
testcase_09 | AC | 64 ms
21,832 KB |
testcase_10 | AC | 59 ms
23,804 KB |
testcase_11 | AC | 68 ms
21,744 KB |
testcase_12 | AC | 86 ms
25,756 KB |
testcase_13 | AC | 66 ms
19,676 KB |
testcase_14 | AC | 70 ms
21,816 KB |
testcase_15 | AC | 80 ms
27,792 KB |
testcase_16 | AC | 69 ms
23,776 KB |
testcase_17 | AC | 82 ms
23,772 KB |
testcase_18 | AC | 95 ms
29,956 KB |
testcase_19 | AC | 87 ms
26,004 KB |
testcase_20 | AC | 82 ms
27,856 KB |
testcase_21 | AC | 62 ms
23,696 KB |
testcase_22 | AC | 80 ms
25,868 KB |
testcase_23 | AC | 85 ms
29,960 KB |
testcase_24 | AC | 82 ms
27,812 KB |
testcase_25 | AC | 73 ms
23,724 KB |
testcase_26 | AC | 87 ms
26,092 KB |
testcase_27 | AC | 77 ms
23,864 KB |
testcase_28 | AC | 72 ms
23,772 KB |
testcase_29 | AC | 88 ms
23,832 KB |
testcase_30 | AC | 85 ms
25,880 KB |
testcase_31 | AC | 83 ms
27,872 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 fromNum = int.Parse(Reader.ReadLine()); int toNum = int.Parse(Reader.ReadLine()); SetPrimeList(toNum); int[] flags = new int[10].Select(a=>-1).ToArray(); int maxlen = 0; int firstPrime = 0; for (int i = 0; i < PrimeList.Length; i++) { if (PrimeList[i] < fromNum) { continue; } if(PrimeList[i]>toNum) { if (i - flags.Where(a=>a>=0).Min()>=maxlen) { firstPrime = PrimeList[flags.Where(a => a >= 0).Min()]; } break; } int prime = PrimeList[i]; int hash = GetHash(prime); if(flags[hash]>=0) { int idx = flags.Where(a => a >= 0).Min(); int len = flags.Where(a => a >= 0).Max() - idx + 1; if (maxlen <= len) { maxlen = len; firstPrime = PrimeList[idx]; } int target = flags[hash]; for (int j = 0; j < flags.Length; j++) { if (flags[j] <= target) { flags[j] = -1; } } } flags[hash] = i; } int lastIdx = flags.Where(a => a >= 0).Min(); int lastLen = flags.Where(a => a >= 0).Max() - lastIdx + 1; if(maxlen <= lastLen) { firstPrime = PrimeList[lastIdx]; } Console.WriteLine(firstPrime); } private int GetHash(int num) { int tmp = num; while(tmp >= 10) { tmp = tmp.ToString().Select(a => int.Parse(a.ToString())).Sum(); } return tmp; } private void SetPrimeList(int num) { bool[] flags = new bool[num + 1]; List<int> tmp = new List<int>(); for (int i = 2; i <= num; i++) { if (flags[i]) { continue; } tmp.Add(i); int max = num / i; for (int j = 1; j <= max; j++) { flags[i * j] = true; } } this.PrimeList = tmp.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 = @" 1 11 "; } public static void Main(string[] args) { #if DEBUG Reader.IsDebug = true; #endif Program prg = new Program(); prg.Proc(); } }