結果

問題 No.390 最長の数列
ユーザー TententenTententen
提出日時 2020-12-14 14:56:02
言語 Java21
(openjdk 21)
結果
AC  
実行時間 1,894 ms / 5,000 ms
コード長 817 bytes
コンパイル時間 2,370 ms
コンパイル使用メモリ 79,652 KB
実行使用メモリ 78,760 KB
最終ジャッジ日時 2023-10-20 05:01:38
合計ジャッジ時間 16,393 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 137 ms
57,304 KB
testcase_01 AC 136 ms
57,272 KB
testcase_02 AC 138 ms
57,512 KB
testcase_03 AC 138 ms
57,468 KB
testcase_04 AC 137 ms
57,492 KB
testcase_05 AC 1,894 ms
76,924 KB
testcase_06 AC 1,673 ms
78,760 KB
testcase_07 AC 136 ms
57,508 KB
testcase_08 AC 138 ms
57,740 KB
testcase_09 AC 139 ms
57,496 KB
testcase_10 AC 1,634 ms
76,868 KB
testcase_11 AC 1,622 ms
76,780 KB
testcase_12 AC 1,676 ms
77,144 KB
testcase_13 AC 1,231 ms
74,656 KB
testcase_14 AC 1,152 ms
76,892 KB
testcase_15 AC 138 ms
57,420 KB
testcase_16 AC 148 ms
57,748 KB
testcase_17 AC 331 ms
62,156 KB
testcase_18 AC 417 ms
62,260 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];
		for (int i = 0; i < n; i++) {
		    arr[i] = sc.nextInt();
		}
		Arrays.sort(arr);
		HashMap<Integer, Integer> map = new HashMap<>();
		int ans = 0;
		for (int i = 0; i < n; i++) {
		    int max = 0;
		    for (int j = 1; j <= Math.sqrt(arr[i]); j++) {
		        if (arr[i] % j == 0) {
		            if (map.containsKey(j)) {
		                max = Math.max(max, map.get(j));
		            }
		            if (map.containsKey(arr[i] / j)) {
		                max = Math.max(max, map.get(arr[i] / j));
		            }
		        }
		    }
		    map.put(arr[i], max + 1);
		    ans = Math.max(ans, max + 1);
		}
		System.out.println(ans);
	}
}
0