結果

問題 No.3009 異なる数字の最大の範囲(勉強会用)
ユーザー yuki2006yuki2006
提出日時 2022-07-11 12:26:25
言語 C#(csc)
(csc 3.9.0)
結果
WA  
実行時間 -
コード長 1,558 bytes
コンパイル時間 3,626 ms
コンパイル使用メモリ 106,204 KB
実行使用メモリ 33,788 KB
最終ジャッジ日時 2023-09-03 17:04:25
合計ジャッジ時間 7,339 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 62 ms
24,520 KB
testcase_02 AC 62 ms
24,392 KB
testcase_03 AC 61 ms
22,268 KB
testcase_04 AC 62 ms
22,376 KB
testcase_05 AC 62 ms
22,420 KB
testcase_06 AC 60 ms
22,396 KB
testcase_07 AC 62 ms
22,324 KB
testcase_08 AC 61 ms
22,332 KB
testcase_09 AC 62 ms
24,308 KB
testcase_10 AC 60 ms
20,380 KB
testcase_11 AC 62 ms
24,288 KB
testcase_12 AC 64 ms
24,368 KB
testcase_13 AC 63 ms
24,244 KB
testcase_14 AC 62 ms
22,448 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 591 ms
33,788 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;

class Program
{
    static void Main()
    {
        int N = int.Parse(Console.ReadLine());
        string[] temp = Console.ReadLine().Split(" ");

        int[] A = new int[temp.Length];
        for (int i = 0; i < temp.Length; i++)
        {
            A[i] = int.Parse(temp[i]);
        }
        // 答えの出力をする
        Console.WriteLine(siraberu(A));
    }
    //ここで調べる
    static int siraberu(int[] A)
    {
        int a = 0;//最長レコード記録
        List<int> siraberukun = new List<int>();//順番に追加していき、かぶっていれば先頭から消していく
        HashSet<int> kaburi = new HashSet<int>();//どの数字が入っているのかを確かめる場所
        for(int b = 0; b < A.Length; b++)
        {
            siraberukun.Add(A[b]);//追加
            if(kaburi.Contains(A[b]))//被っているものがあった場合
            {
                bool c = true;
                while (c)//先頭から調べて被ったやつを探す
                {
                    if(siraberukun[0] == A[b] || (siraberukun.Count == 1))
                        c = false;//ループを終わらせるよぅ
                    siraberukun.RemoveAt(0);//1番目にさよならを告げる
                }
            }
            else//まだ被っていない数字だった場合
                kaburi.Add(A[b]);//登録
            if (a < siraberukun.Count)
                a = siraberukun.Count;
        }
        return a;
    }
}
0