結果
問題 | No.6 使いものにならないハッシュ |
ユーザー |
![]() |
提出日時 | 2016-03-30 13:34:02 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
AC
|
実行時間 | 56 ms / 5,000 ms |
コード長 | 3,424 bytes |
コンパイル時間 | 873 ms |
コンパイル使用メモリ | 113,316 KB |
実行使用メモリ | 21,888 KB |
最終ジャッジ日時 | 2024-09-16 16:32:53 |
合計ジャッジ時間 | 3,096 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 32 |
コンパイルメッセージ
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; public class Program { public void Proc() { Reader.IsDebug = false; int min = int.Parse(Reader.ReadLine()); int max = int.Parse(Reader.ReadLine()); this.CreatePrimeList(min,max); int maxLength = 1; int startIdx = 0; int ans = -1; Dictionary<int, int> hashCount = new Dictionary<int, int>(); hashCount[HashList[0]] = 1; for(int i=0; i<PrimeList.Count; i++) { if(startIdx == i) { continue; } int hash = HashList[i]; if(hashCount.ContainsKey(hash)) { for(int j=startIdx; j<i; j++) { hashCount[HashList[j]]--; if(hashCount[HashList[j]] <= 0) { hashCount.Remove(HashList[j]); } if(HashList[j] == hash) { hashCount.Add(hash, 1); startIdx = j + 1; break; } } } else { hashCount.Add(hash, 1); } if(hashCount.Count >= maxLength) { ans = PrimeList[startIdx]; maxLength = hashCount.Count; } } if(maxLength == 1) { ans = PrimeList[PrimeList.Count - 1]; } Console.WriteLine(ans); } private List<int> PrimeList = new List<int>(); private List<int> HashList = new List<int>(); private void CreatePrimeList(int min, int max) { bool[] isProc = new bool[max + 1]; for(int i=2; i<=max; i++) { if (isProc[i] == false) { isProc[i] = true; if(i >= min) { PrimeList.Add(i); int tmpNum = i; while (tmpNum >= 10) { int total = 0; string strTemp = tmpNum.ToString(); foreach (char c in strTemp) { total += int.Parse(c.ToString()); } tmpNum = total; } HashList.Add(tmpNum); } for (int j = 1; j<=max / i; j++) { isProc[i * j] = true; } } } } public class Reader { private static String InitText = @" 10 100 "; private static System.IO.StringReader sr = null; public static bool IsDebug = true; public static string ReadLine() { if(IsDebug) { if(sr == null) { sr = new System.IO.StringReader(InitText.Trim()); } return sr.ReadLine(); } else { return Console.ReadLine(); } } public static int[] GetInt(char delimiter = ' ') { string[] inpt = ReadLine().Split(delimiter); int[] ret = new int[inpt.Length]; for(int i=0; i<inpt.Length; i++) { ret[i] = int.Parse(inpt[i]); } return ret; } } public static void Main(string[] args) { Program prg = new Program(); prg.Proc(); } }