結果
| 問題 | No.390 最長の数列 |
| コンテスト | |
| ユーザー |
tenten
|
| 提出日時 | 2020-09-29 13:54:41 |
| 言語 | Java (openjdk 25.0.2) |
| 結果 |
AC
|
| 実行時間 | 1,465 ms / 5,000 ms |
| コード長 | 1,064 bytes |
| 記録 | |
| コンパイル時間 | 1,718 ms |
| コンパイル使用メモリ | 85,520 KB |
| 実行使用メモリ | 87,800 KB |
| 最終ジャッジ日時 | 2026-03-25 03:56:44 |
| 合計ジャッジ時間 | 14,616 ms |
|
ジャッジサーバーID (参考情報) |
judge2_0 / judge1_1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 15 |
ソースコード
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;
}
}
tenten