結果

問題 No.3009 異なる数字の最大の範囲(勉強会用)
ユーザー uafr_csuafr_cs
提出日時 2015-08-12 00:56:00
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 674 bytes
コンパイル時間 2,826 ms
コンパイル使用メモリ 78,456 KB
実行使用メモリ 66,608 KB
最終ジャッジ日時 2023-09-03 16:52:37
合計ジャッジ時間 10,982 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 126 ms
55,772 KB
testcase_02 AC 122 ms
56,012 KB
testcase_03 AC 124 ms
55,892 KB
testcase_04 AC 121 ms
55,584 KB
testcase_05 WA -
testcase_06 AC 123 ms
55,880 KB
testcase_07 AC 122 ms
55,812 KB
testcase_08 AC 124 ms
55,528 KB
testcase_09 AC 125 ms
55,824 KB
testcase_10 AC 126 ms
55,944 KB
testcase_11 AC 123 ms
55,164 KB
testcase_12 AC 125 ms
55,492 KB
testcase_13 AC 127 ms
55,648 KB
testcase_14 AC 128 ms
55,624 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 565 ms
66,608 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Scanner;
import java.util.Set;

public class Main {
	
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		final int N = sc.nextInt();
		int[] arr = new int[N];
		for(int i = 0; i < N; i++){
			arr[i] = sc.nextInt();
		}
		
		int max = 0;
		Map<Integer, Integer> map = new HashMap<Integer, Integer>();
		
		int left = 0;
		for(int i = 0; i < N; i++){
			if(map.containsKey(arr[i])){
				max = Math.max(max, i - left);
				left = map.get(arr[i]) + 1;
			}
			map.put(arr[i], i);
		}
		max = Math.max(max, N - left);
		
		System.out.println(max);
	}
	
}
0