結果
問題 | No.390 最長の数列 |
ユーザー |
![]() |
提出日時 | 2020-12-14 14:56:02 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 1,603 ms / 5,000 ms |
コード長 | 817 bytes |
コンパイル時間 | 1,966 ms |
コンパイル使用メモリ | 78,976 KB |
実行使用メモリ | 74,748 KB |
最終ジャッジ日時 | 2024-09-20 00:43:58 |
合計ジャッジ時間 | 13,960 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
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); } }