結果
| 問題 |
No.12 限定された素数
|
| コンテスト | |
| ユーザー |
バカらっく
|
| 提出日時 | 2017-06-28 02:51:16 |
| 言語 | C#(csc) (csc 3.9.0) |
| 結果 |
AC
|
| 実行時間 | 330 ms / 5,000 ms |
| コード長 | 2,741 bytes |
| コンパイル時間 | 2,606 ms |
| コンパイル使用メモリ | 115,784 KB |
| 実行使用メモリ | 42,800 KB |
| 最終ジャッジ日時 | 2024-11-24 09:59:32 |
| 合計ジャッジ時間 | 7,680 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 26 |
コンパイルメッセージ
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 itemCount = int.Parse(Reader.ReadLine());
char[] items = Reader.ReadLine().Split(' ').Select(a => a[0]).ToArray();
this.PrimeList = this.GetPrimeList();
int fromIdx = -1;
int toIdx = -1;
int ans = -1;
Dictionary<char, bool> cnt = new Dictionary<char, bool>();
items.ToList().ForEach(a=>cnt.Add(a, false));
for (int i = 0; i < PrimeList.Length; i++) {
string num = PrimeList[i].ToString();
if(num.All(a=>cnt.ContainsKey(a))) {
if (fromIdx < 0) {
fromIdx = i;
}
toIdx = i;
num.ToList().ForEach(a => cnt[a] = true);
} else {
if (fromIdx >= 0 && cnt.All(a=>a.Value)) {
int fromNum = 1;
if (fromIdx > 0) {
fromNum = PrimeList[fromIdx-1]+1;
}
int toNum = 5000000;
if(toIdx < PrimeList.Length - 1) {
toNum = PrimeList[toIdx + 1] - 1;
}
ans = Math.Max(ans, toNum - fromNum);
}
fromIdx = -1;
toIdx = -1;
cnt.Keys.ToList().ForEach(a => cnt[a] = false);
}
}
if(toIdx >= 0) {
int fromNum = 1;
if (fromIdx>0) {
fromNum = PrimeList[fromIdx - 1] + 1;
}
ans = Math.Max(ans, 5000000 - fromNum);
}
Console.WriteLine(ans);
}
private int[] GetPrimeList() {
int num = 5000000;
bool[] flags = new bool[num + 1];
List<int> ret = new List<int>();
for (int i = 2; i <= num; i++) {
if (flags[i]) {
continue;
}
ret.Add(i);
int max = num / i;
for (int j = 0; j <= max; j++) {
flags[i*j] = true;
}
}
return ret.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 = @"
5
1 2 3 4 5
";
}
public static void Main(string[] args)
{
#if DEBUG
Reader.IsDebug = true;
#endif
Program prg = new Program();
prg.Proc();
}
}
バカらっく