結果
問題 |
No.979 Longest Divisor Sequence
|
ユーザー |
![]() |
提出日時 | 2020-02-06 12:52:14 |
言語 | Java (openjdk 23) |
結果 |
TLE
(最新)
AC
(最初)
|
実行時間 | - |
コード長 | 926 bytes |
コンパイル時間 | 2,700 ms |
コンパイル使用メモリ | 77,212 KB |
実行使用メモリ | 82,824 KB |
最終ジャッジ日時 | 2024-09-25 06:44:28 |
合計ジャッジ時間 | 10,705 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 15 TLE * 1 |
ソースコード
import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); HashMap<Integer, Integer> map = new HashMap<>(); int ans = 1; for (int i = 0; i < n; i++) { int max = 0; int x = sc.nextInt(); if (map.containsKey(1) && x != 1) { max = 1; } for (int j = 2; j <= Math.sqrt(x); j++) { if (x % j == 0) { if (map.containsKey(j)) { max = Math.max(max, map.get(j)); } if (map.containsKey(x / j)) { max = Math.max(max, map.get(x / j)); } } } map.put(x, max + 1); ans = Math.max(ans, max + 1); } System.out.println(ans); } }