結果

問題 No.3009 異なる数字の最大の範囲(勉強会用)
ユーザー tentententen
提出日時 2021-02-12 12:08:39
言語 Java21
(openjdk 21)
結果
AC  
実行時間 586 ms / 5,000 ms
コード長 733 bytes
コンパイル時間 2,608 ms
コンパイル使用メモリ 75,384 KB
実行使用メモリ 65,360 KB
最終ジャッジ日時 2024-04-30 17:45:37
合計ジャッジ時間 9,764 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 125 ms
55,956 KB
testcase_01 AC 127 ms
54,304 KB
testcase_02 AC 128 ms
53,796 KB
testcase_03 AC 125 ms
54,040 KB
testcase_04 AC 123 ms
53,808 KB
testcase_05 AC 128 ms
53,912 KB
testcase_06 AC 114 ms
53,152 KB
testcase_07 AC 114 ms
52,728 KB
testcase_08 AC 124 ms
54,188 KB
testcase_09 AC 129 ms
54,368 KB
testcase_10 AC 126 ms
54,024 KB
testcase_11 AC 125 ms
53,976 KB
testcase_12 AC 128 ms
53,920 KB
testcase_13 AC 127 ms
54,104 KB
testcase_14 AC 124 ms
54,156 KB
testcase_15 AC 522 ms
59,364 KB
testcase_16 AC 525 ms
59,292 KB
testcase_17 AC 512 ms
59,268 KB
testcase_18 AC 586 ms
59,488 KB
testcase_19 AC 561 ms
59,424 KB
testcase_20 AC 419 ms
59,164 KB
testcase_21 AC 312 ms
58,832 KB
testcase_22 AC 483 ms
59,144 KB
testcase_23 AC 347 ms
58,916 KB
testcase_24 AC 583 ms
65,360 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++;
                }
                left++;
            } else {
                exist.add(arr[i]);
                max = Math.max(max, i - left + 1);
            }
        }
        System.out.println(max);
    }
}
0