結果

問題 No.6 使いものにならないハッシュ
ユーザー 14番14番
提出日時 2016-03-30 13:34:02
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 81 ms / 5,000 ms
コード長 3,424 bytes
コンパイル時間 2,946 ms
コンパイル使用メモリ 107,684 KB
実行使用メモリ 27,136 KB
最終ジャッジ日時 2023-10-14 22:58:45
合計ジャッジ時間 6,301 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 55 ms
22,756 KB
testcase_01 AC 56 ms
20,756 KB
testcase_02 AC 80 ms
27,136 KB
testcase_03 AC 61 ms
22,752 KB
testcase_04 AC 62 ms
22,760 KB
testcase_05 AC 64 ms
20,756 KB
testcase_06 AC 69 ms
24,744 KB
testcase_07 AC 63 ms
20,756 KB
testcase_08 AC 68 ms
20,816 KB
testcase_09 AC 64 ms
22,844 KB
testcase_10 AC 55 ms
20,780 KB
testcase_11 AC 61 ms
22,908 KB
testcase_12 AC 74 ms
22,808 KB
testcase_13 AC 60 ms
18,708 KB
testcase_14 AC 62 ms
20,892 KB
testcase_15 AC 70 ms
20,712 KB
testcase_16 AC 66 ms
22,856 KB
testcase_17 AC 74 ms
22,796 KB
testcase_18 AC 81 ms
23,108 KB
testcase_19 AC 74 ms
22,848 KB
testcase_20 AC 68 ms
24,900 KB
testcase_21 AC 59 ms
22,828 KB
testcase_22 AC 71 ms
24,848 KB
testcase_23 AC 69 ms
22,848 KB
testcase_24 AC 71 ms
22,904 KB
testcase_25 AC 64 ms
20,756 KB
testcase_26 AC 75 ms
22,956 KB
testcase_27 AC 71 ms
22,812 KB
testcase_28 AC 66 ms
22,696 KB
testcase_29 AC 77 ms
22,728 KB
testcase_30 AC 75 ms
22,812 KB
testcase_31 AC 72 ms
22,808 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

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();
    }
}
0