結果
問題 |
No.8009 異なる数字の最大の範囲(勉強会用)
|
ユーザー |
|
提出日時 | 2015-02-28 17:16:36 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
AC
|
実行時間 | 73 ms / 5,000 ms |
コード長 | 1,591 bytes |
コンパイル時間 | 3,877 ms |
コンパイル使用メモリ | 113,576 KB |
実行使用メモリ | 39,788 KB |
最終ジャッジ日時 | 2024-11-20 14:59:49 |
合計ジャッジ時間 | 4,446 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 22 |
コンパイルメッセージ
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.Collections; namespace Application { class MainClass { public static void Main (string[] args) { var N = readInt (); var A = readInts (' '); var s = new Searcher (); var l = 0; while (l < N) { l = s.LonguestSeq (A, l); } writeLine (s.Longest); } public class Searcher { public int Longest = 0; private Queue<int> distinct = new Queue<int> (); private Dictionary<int, bool> dict = new Dictionary<int, bool>(); public int LonguestSeq (int[] A, int l) { var i = l + distinct.Count; for (; i < A.Length && !dict.ContainsKey (A [i]); i++) { distinct.Enqueue (A [i]); dict.Add(A[i], true); } this.Longest = Math.Max (distinct.Count, this.Longest); while (true) { l++; if (distinct.Count == 0) break; if (A.Length <= i) break; var value = distinct.Dequeue (); dict.Remove(value); if (A [i] == value) break; } var rest = A.Length - l; if (this.Longest > (rest + distinct.Count)) l = A.Length; return l; } } static void writeLine (object o) { System.Console.WriteLine (o.ToString ()); } static string readItem () { return readItems (' ') [0]; } static String[] readItems (char c) { return System.Console.ReadLine ().Split (c); } static int readInt () { return readInts (' ') [0]; } static int[] readInts (char c) { return readItems (c).Select (x => int.Parse (x)).ToArray (); } } }