結果
問題 | No.390 最長の数列 |
ユーザー | htensai |
提出日時 | 2019-11-20 13:24:08 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 1,901 ms / 5,000 ms |
コード長 | 922 bytes |
コンパイル時間 | 2,131 ms |
コンパイル使用メモリ | 78,948 KB |
実行使用メモリ | 80,696 KB |
最終ジャッジ日時 | 2024-04-15 22:11:32 |
合計ジャッジ時間 | 16,575 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 124 ms
41,004 KB |
testcase_01 | AC | 130 ms
41,364 KB |
testcase_02 | AC | 130 ms
41,288 KB |
testcase_03 | AC | 126 ms
41,204 KB |
testcase_04 | AC | 115 ms
40,148 KB |
testcase_05 | AC | 1,901 ms
80,696 KB |
testcase_06 | AC | 1,678 ms
65,604 KB |
testcase_07 | AC | 129 ms
41,472 KB |
testcase_08 | AC | 130 ms
41,504 KB |
testcase_09 | AC | 128 ms
41,208 KB |
testcase_10 | AC | 1,789 ms
76,024 KB |
testcase_11 | AC | 1,794 ms
75,864 KB |
testcase_12 | AC | 1,875 ms
75,828 KB |
testcase_13 | AC | 1,204 ms
61,532 KB |
testcase_14 | AC | 1,152 ms
65,436 KB |
testcase_15 | AC | 115 ms
40,316 KB |
testcase_16 | AC | 139 ms
41,364 KB |
testcase_17 | AC | 323 ms
47,252 KB |
testcase_18 | AC | 391 ms
49,268 KB |
ソースコード
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); } }