結果

問題 No.979 Longest Divisor Sequence
ユーザー htensai
提出日時 2020-02-06 12:59:57
言語 Java
(openjdk 23)
結果
AC  
実行時間 1,819 ms / 2,000 ms
コード長 730 bytes
コンパイル時間 2,192 ms
コンパイル使用メモリ 78,020 KB
実行使用メモリ 58,672 KB
最終ジャッジ日時 2024-09-25 06:45:06
合計ジャッジ時間 8,801 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 16
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] map = new int[300001];
        int ans = 1;
        for (int i = 0; i < n; i++) {
            int max = 0;
            int x = sc.nextInt();
            if (x != 1) {
                max = map[1];
            }
            for (int j = 2; j <= Math.sqrt(x); j++) {
                if (x % j == 0) {
                    max = Math.max(max, map[j]);
                    max = Math.max(max, map[x / j]);
                }
            }
            map[x] = max + 1;
            ans = Math.max(ans, max + 1);
        }
        System.out.println(ans);
    }
}
0