結果
問題 | No.390 最長の数列 |
ユーザー | tenten |
提出日時 | 2020-09-29 13:54:41 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 2,205 ms / 5,000 ms |
コード長 | 1,064 bytes |
コンパイル時間 | 3,315 ms |
コンパイル使用メモリ | 76,044 KB |
実行使用メモリ | 105,532 KB |
最終ジャッジ日時 | 2023-09-16 21:22:17 |
合計ジャッジ時間 | 19,089 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge13 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 124 ms
55,764 KB |
testcase_01 | AC | 124 ms
55,992 KB |
testcase_02 | AC | 125 ms
56,484 KB |
testcase_03 | AC | 124 ms
55,844 KB |
testcase_04 | AC | 128 ms
56,140 KB |
testcase_05 | AC | 2,072 ms
105,532 KB |
testcase_06 | AC | 2,205 ms
79,648 KB |
testcase_07 | AC | 124 ms
55,808 KB |
testcase_08 | AC | 124 ms
55,788 KB |
testcase_09 | AC | 125 ms
56,144 KB |
testcase_10 | AC | 2,074 ms
90,852 KB |
testcase_11 | AC | 1,924 ms
89,244 KB |
testcase_12 | AC | 1,942 ms
90,016 KB |
testcase_13 | AC | 1,152 ms
71,960 KB |
testcase_14 | AC | 1,378 ms
78,712 KB |
testcase_15 | AC | 124 ms
56,200 KB |
testcase_16 | AC | 174 ms
57,492 KB |
testcase_17 | AC | 415 ms
68,532 KB |
testcase_18 | AC | 548 ms
69,520 KB |
ソースコード
import java.util.*; public class Main { static HashSet<Integer> exists = new HashSet<>(); static TreeMap<Integer, Integer> dp = new TreeMap<>(); public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); for (int i = 0; i < n; i++) { exists.add(sc.nextInt()); } int max = 0; for (int x : exists) { max = Math.max(max, dfw(x)); } System.out.println(max); } static int dfw(int x) { if (dp.containsKey(x)) { return dp.get(x); } if (!exists.contains(x)) { dp.put(x, 0); return 0; } if (x == 1) { dp.put(x, 1); return 1; } int max = dfw(1); for (int i = 2; i <= Math.sqrt(x); i++) { if (x % i == 0) { max = Math.max(max, dfw(i)); max = Math.max(max, dfw(x / i)); } } dp.put(x, max + 1); return max + 1; } }