結果
| 問題 | No.390 最長の数列 |
| コンテスト | |
| ユーザー |
Tententen
|
| 提出日時 | 2020-12-14 14:56:02 |
| 言語 | Java (openjdk 25.0.2) |
| 結果 |
AC
|
| 実行時間 | 834 ms / 5,000 ms |
| コード長 | 817 bytes |
| 記録 | |
| コンパイル時間 | 1,908 ms |
| コンパイル使用メモリ | 84,484 KB |
| 実行使用メモリ | 67,160 KB |
| 最終ジャッジ日時 | 2026-04-08 13:09:51 |
| 合計ジャッジ時間 | 9,037 ms |
|
ジャッジサーバーID (参考情報) |
judge1_0 / judge3_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 15 |
ソースコード
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);
}
}
Tententen