結果

問題 No.8009 異なる数字の最大の範囲(勉強会用)
ユーザー uafr_cs
提出日時 2015-08-12 00:56:00
言語 Java
(openjdk 23)
結果
WA  
実行時間 -
コード長 674 bytes
コンパイル時間 3,775 ms
コンパイル使用メモリ 84,572 KB
実行使用メモリ 63,960 KB
最終ジャッジ日時 2024-06-12 22:30:26
合計ジャッジ時間 10,843 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 11 WA * 11
権限があれば一括ダウンロードができます

ソースコード

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