結果

問題 No.390 最長の数列
ユーザー htensai
提出日時 2019-11-20 13:24:08
言語 Java
(openjdk 23)
結果
AC  
実行時間 1,742 ms / 5,000 ms
コード長 922 bytes
コンパイル時間 2,523 ms
コンパイル使用メモリ 79,012 KB
実行使用メモリ 80,436 KB
最終ジャッジ日時 2024-10-06 04:05:26
合計ジャッジ時間 16,049 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 15
権限があれば一括ダウンロードができます

ソースコード

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];
		for (int i = 0; i < n; i++) {
		    arr[i] = sc.nextInt();
		}
		Arrays.sort(arr);
		HashMap<Integer, Integer> map = new HashMap<>();
		int max = 1;
		for (int i = n - 1; i >= 0; i--) {
		    int count = 1;
		    if (map.containsKey(arr[i])) {
		        count = map.get(arr[i]) + 1;
		    }
		    max = Math.max(max, count);
		    for (int j = 1; j <= Math.sqrt(arr[i]); j++) {
		        if (arr[i] % j == 0) {
		            Integer x = map.get(j);
		            if (x == null || x < count) {
		                map.put(j, count);
		            }
		            x = map.get(arr[i] / j);
		            if (x == null || x < count) {
		                map.put(arr[i] / j, count);
		            }
		        }
		    }
		}
		System.out.println(max);
	}
}
0