結果
| 問題 | No.6 使いものにならないハッシュ | 
| コンテスト | |
| ユーザー |  バカらっく | 
| 提出日時 | 2017-06-25 16:42:45 | 
| 言語 | C#(csc) (csc 3.9.0) | 
| 結果 | 
                                WA
                                 
                             | 
| 実行時間 | - | 
| コード長 | 2,512 bytes | 
| コンパイル時間 | 862 ms | 
| コンパイル使用メモリ | 108,800 KB | 
| 実行使用メモリ | 23,360 KB | 
| 最終ジャッジ日時 | 2024-10-04 08:55:52 | 
| 合計ジャッジ時間 | 3,258 ms | 
| ジャッジサーバーID (参考情報) | judge3 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 28 WA * 4 | 
コンパイルメッセージ
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;
        }
        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 = @"
10
100
";
	}
	public static void Main(string[] args)
	{
#if DEBUG
		Reader.IsDebug = true;
#endif
		Program prg = new Program();
		prg.Proc();
	}
}
            
            
            
        