結果

問題 No.3009 異なる数字の最大の範囲(勉強会用)
ユーザー tentententen
提出日時 2021-02-12 10:30:23
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 709 bytes
コンパイル時間 2,722 ms
コンパイル使用メモリ 72,332 KB
実行使用メモリ 66,840 KB
最終ジャッジ日時 2023-09-03 17:00:22
合計ジャッジ時間 9,318 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 AC 112 ms
55,532 KB
testcase_03 AC 109 ms
56,064 KB
testcase_04 AC 109 ms
55,796 KB
testcase_05 WA -
testcase_06 AC 108 ms
55,820 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 109 ms
56,028 KB
testcase_10 AC 111 ms
55,576 KB
testcase_11 AC 108 ms
55,744 KB
testcase_12 AC 104 ms
56,016 KB
testcase_13 WA -
testcase_14 WA -
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 491 ms
66,840 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] arr = new int[n];
        HashSet<Integer> exist = new HashSet<>();
        int left = 0;
        int max = 0;
        for (int i = 0; i < n; i++) {
            arr[i] = sc.nextInt();
            if (exist.contains(arr[i])) {
                while (arr[left] != arr[i]) {
                    exist.remove(arr[left]);
                    left++;
                }
            } else {
                exist.add(arr[i]);
                max = Math.max(max, i - left + 1);
            }
        }
        System.out.println(max);
    }
}
0