結果
| 問題 |
No.6 使いものにならないハッシュ
|
| コンテスト | |
| ユーザー |
mban
|
| 提出日時 | 2016-11-01 04:22:37 |
| 言語 | C#(csc) (csc 3.9.0) |
| 結果 |
AC
|
| 実行時間 | 31 ms / 5,000 ms |
| コード長 | 2,229 bytes |
| コンパイル時間 | 1,033 ms |
| コンパイル使用メモリ | 112,740 KB |
| 実行使用メモリ | 19,840 KB |
| 最終ジャッジ日時 | 2024-09-16 16:37:36 |
| 合計ジャッジ時間 | 2,862 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| 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;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
class Magatro
{
static int N, K;
static List<int> Prime = new List<int>(),hash=new List<int>();
static bool[] flag = new bool[10];
static void Main()
{
Read();
Primecnt();
Hashcalc();
int migi = 0;
int hidari = 0;
int max=0;
int first = 0;
for (int i = 0; i < Prime.Count; i++)
{
if (!flag[hash[i]])
{
migi++;
flag[hash[i]] = true;
}
else
{
if (migi - hidari + 1 >= max) {
max = migi - hidari + 1;
first = hidari;
}
for (int j = hidari; hash[i] != hash[j]; j++)
{
hidari++;
flag[hash[j]] = false;
}
hidari++;
migi++;
// flag[hash[i]] = false;
}
}
if (migi - hidari + 1 >= max)
{
max = migi - hidari + 1;
first = hidari;
}
Console.WriteLine(Prime[first]);
}
static void Hashcalc()
{
for(int i = 0; i <Prime.Count; i++)
{
hash.Add(calc(calc(calc((Prime[i])))));
}
}
static int calc(int n)
{
if (n<10)
{
return n;
}
return calc(n / 10) + n % 10;
}
static void Primecnt()
{
bool[] n = (new bool[N + 1]).Select(s => true).ToArray();
n[0] = false;
n[1] = false;
int rootN = (int)Math.Sqrt(N) + 1;
for (int i = 2; i <= rootN; i++)
{
if (n[i])
{
for (int j = i + i; j <= N; j += i)
{
n[j] = false;
}
}
}
for (int i = K; i <= N; i++)
{
if (n[i])
{
Prime.Add(i);
}
}
}
static void Read()
{
K = int.Parse(Console.ReadLine());
N = int.Parse(Console.ReadLine());
}
}
mban