結果

問題 No.3009 異なる数字の最大の範囲(勉強会用)
ユーザー yuki2006yuki2006
提出日時 2015-02-28 03:27:22
言語 Java21
(openjdk 21)
結果
AC  
実行時間 582 ms / 5,000 ms
コード長 1,363 bytes
コンパイル時間 3,770 ms
コンパイル使用メモリ 75,648 KB
実行使用メモリ 59,480 KB
最終ジャッジ日時 2024-04-30 17:42:11
合計ジャッジ時間 10,026 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 105 ms
52,764 KB
testcase_01 AC 115 ms
54,080 KB
testcase_02 AC 102 ms
52,936 KB
testcase_03 AC 118 ms
54,156 KB
testcase_04 AC 103 ms
52,900 KB
testcase_05 AC 107 ms
52,716 KB
testcase_06 AC 113 ms
53,856 KB
testcase_07 AC 106 ms
53,328 KB
testcase_08 AC 109 ms
53,848 KB
testcase_09 AC 114 ms
53,856 KB
testcase_10 AC 113 ms
54,024 KB
testcase_11 AC 118 ms
54,244 KB
testcase_12 AC 112 ms
54,024 KB
testcase_13 AC 100 ms
54,676 KB
testcase_14 AC 110 ms
53,900 KB
testcase_15 AC 457 ms
59,000 KB
testcase_16 AC 401 ms
59,204 KB
testcase_17 AC 458 ms
59,320 KB
testcase_18 AC 582 ms
59,436 KB
testcase_19 AC 475 ms
59,480 KB
testcase_20 AC 391 ms
59,228 KB
testcase_21 AC 277 ms
58,784 KB
testcase_22 AC 490 ms
59,476 KB
testcase_23 AC 287 ms
58,876 KB
testcase_24 AC 433 ms
58,896 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

public class Yuki3009 {


    public Yuki3009() {
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        int[] data = new int[N];
        for (int i = 0; i < N; i++) {
            data[i] = scanner.nextInt();
        }
        int L = 0;
        int R = 0;
        boolean[] checked = new boolean[1000000 + 1];
        int max = 0;
        // しゃくとり法
        // Rが最終点までいけば、それ以上更新されないため。
        while (R < data.length) {
            int c = data[R];
            if (checked[c]) {
                //すでにチェックされているものがあれば、長さを更新する。
                max = Math.max(max, R - L);
                //L側を横にずらすのでチェックから外す。
                final int Lc = data[L];
                checked[Lc] = false;
                //L側を横にずらす。
                L++;
            } else {
                //普通にRをを横にずらす。
                R++;
                checked[c] = true;
            }
        }
        //最後まで連続した文字の場合のために更新する。
        max = Math.max(max, R - L);
        System.out.println(max);
    }

    public static void main(String[] args) {
        Yuki3009 hoge = new Yuki3009();
    }
}

0