AtCoderのARC
次のARCの問題へ
前のARCの問題へ
ARC022-B 細長いお菓子
C#のソース
using System;
using System.Collections.Generic;
using System.Linq;
class Program
{
static string InputPattern = "InputX";
static List<string> GetInputList()
{
var WillReturn = new List<string>();
if (InputPattern == "Input1") {
WillReturn.Add("7");
WillReturn.Add("1 2 1 3 1 4 4");
//3
}
else if (InputPattern == "Input2") {
WillReturn.Add("1");
WillReturn.Add("100");
//1
}
else {
string wkStr;
while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr);
}
return WillReturn;
}
static void Main()
{
List<string> InputList = GetInputList();
int[] AArr = InputList[1].Split(' ').Select(pX => int.Parse(pX)).ToArray();
int UB = AArr.GetUpperBound(0);
int Answer = int.MinValue;
var ASet = new HashSet<int>();
ASet.Add(AArr[0]);
int R = 0;
for (int L = 0; L <= UB; L++) {
while (R + 1 <= UB && ASet.Add(AArr[R + 1])) {
R++;
}
Answer = Math.Max(Answer, ASet.Count);
ASet.Remove(AArr[L]);
}
Console.WriteLine(Answer);
}
}
解説
尺取法で解いてます。