結果

問題 No.3009 異なる数字の最大の範囲(勉強会用)
ユーザー 明智重蔵明智重蔵
提出日時 2015-07-26 20:35:02
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 230 ms / 5,000 ms
コード長 1,892 bytes
コンパイル時間 1,063 ms
コンパイル使用メモリ 118,580 KB
実行使用メモリ 52,204 KB
最終ジャッジ日時 2024-04-30 17:43:00
合計ジャッジ時間 3,931 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
25,776 KB
testcase_01 AC 41 ms
26,032 KB
testcase_02 AC 41 ms
27,688 KB
testcase_03 AC 38 ms
27,772 KB
testcase_04 AC 39 ms
23,860 KB
testcase_05 AC 41 ms
27,692 KB
testcase_06 AC 39 ms
27,436 KB
testcase_07 AC 40 ms
25,776 KB
testcase_08 AC 40 ms
25,648 KB
testcase_09 AC 42 ms
25,772 KB
testcase_10 AC 40 ms
23,344 KB
testcase_11 AC 38 ms
27,644 KB
testcase_12 AC 39 ms
25,904 KB
testcase_13 AC 40 ms
25,520 KB
testcase_14 AC 40 ms
25,900 KB
testcase_15 AC 125 ms
43,376 KB
testcase_16 AC 116 ms
40,024 KB
testcase_17 AC 121 ms
43,060 KB
testcase_18 AC 230 ms
52,204 KB
testcase_19 AC 142 ms
42,564 KB
testcase_20 AC 85 ms
38,236 KB
testcase_21 AC 56 ms
29,080 KB
testcase_22 AC 92 ms
37,336 KB
testcase_23 AC 61 ms
29,196 KB
testcase_24 AC 115 ms
51,488 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

using System;
using System.Collections.Generic;
using System.Linq;

class Program
{
    static string InputPattern = "Input4";

    static List<string> GetInputList()
    {
        var WillReturn = new List<string>();

        if (InputPattern == "Input1") {
            WillReturn.Add("5");
            WillReturn.Add("1 2 3 1 2");
        }
        else if (InputPattern == "Input2") {
            WillReturn.Add("5");
            WillReturn.Add("1 2 3 4 5");
        }
        else if (InputPattern == "Input3") {
            WillReturn.Add("5");
            WillReturn.Add("1 1 1 1 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(X => int.Parse(X)).ToArray();

        int UB = AArr.GetUpperBound(0);

        //重複のあるデータを昇順で保持
        int[] DupValArr = AArr.GroupBy(X => X).
            Select(X => new { X.Key, cnt = X.Count() }).Where(X => X.cnt > 1).
            Select(X => X.Key).OrderBy(X => X).ToArray();

        int Answer = 0;

        int L = 0;
        for (int R = 0; R <= UB; R++) {
            int CurrVal = AArr[R];

            if (Array.BinarySearch<int>(DupValArr, CurrVal) >= 0) {
                //再登場の数値の場合
                int wkInd = Array.FindIndex(AArr, L, R - L, X => X == CurrVal);
                if (wkInd >= 0) {
                    L = wkInd + 1;

                    //下限値枝切り
                    int RestMaxCnt = UB - L + 1;
                    if (RestMaxCnt <= Answer) break;
                }
            }

            if (Answer < R - L + 1)
                Answer = R - L + 1;
        }
        Console.WriteLine(Answer);
    }
}
0